remove $Id keyword

This commit is contained in:
markpollack
2008-06-02 20:18:24 +00:00
parent 08227919f1
commit c33ba2dea5
1275 changed files with 144209 additions and 145452 deletions

View File

@@ -1,56 +1,55 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using Spring.Objects.Factory.Xml;
namespace Spring.Aop.Config
{
/// <summary>
/// Namespace parser for the aop namespace.
/// </summary>
/// <remarks>
/// Using the <code>advisor</code> tag you can configure an <see cref="IAdvisor"/> and have it
/// applied to all the relevant objects in your application context automatically. The
/// <code>advisor</code> tag supports only referenced <see cref="IPointcut"/>s.
/// </remarks>
/// <author>Rob harrop</author>
/// <author>Adrian Colyer</author>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: AopNamespaceParser.cs,v 1.3 2007/08/09 02:42:35 markpollack Exp $</version>
[
NamespaceParser(
Namespace = "http://www.springframework.net/aop",
SchemaLocationAssemblyHint = typeof (AopNamespaceParser),
SchemaLocation = "/Spring.Aop.Config/spring-aop-1.1.xsd"
)
]
public class AopNamespaceParser : NamespaceParserSupport
{
/// <summary>
/// Register the <see cref="IObjectDefinitionParser"/> for the '<code>config</code>' tag.
/// </summary>
public override void Init()
{
RegisterObjectDefinitionParser("config", new ConfigObjectDefinitionParser());
}
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using Spring.Objects.Factory.Xml;
namespace Spring.Aop.Config
{
/// <summary>
/// Namespace parser for the aop namespace.
/// </summary>
/// <remarks>
/// Using the <code>advisor</code> tag you can configure an <see cref="IAdvisor"/> and have it
/// applied to all the relevant objects in your application context automatically. The
/// <code>advisor</code> tag supports only referenced <see cref="IPointcut"/>s.
/// </remarks>
/// <author>Rob harrop</author>
/// <author>Adrian Colyer</author>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
[
NamespaceParser(
Namespace = "http://www.springframework.net/aop",
SchemaLocationAssemblyHint = typeof (AopNamespaceParser),
SchemaLocation = "/Spring.Aop.Config/spring-aop-1.1.xsd"
)
]
public class AopNamespaceParser : NamespaceParserSupport
{
/// <summary>
/// Register the <see cref="IObjectDefinitionParser"/> for the '<code>config</code>' tag.
/// </summary>
public override void Init()
{
RegisterObjectDefinitionParser("config", new ConfigObjectDefinitionParser());
}
}
}

View File

@@ -1,99 +1,98 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Xml;
using Spring.Aop.Framework.AutoProxy;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
#endregion
namespace Spring.Aop.Config
{
/// <summary>
/// Utility class for handling registration of auto-proxy creators used internally by the
/// <code>aop</code> namespace tags.
/// </summary>
/// <author>Rob Harrop</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: AopNamespaceUtils.cs,v 1.4 2007/05/26 19:25:48 markpollack Exp $</version>
public class AopNamespaceUtils
{
/// <summary>
/// The object name of the internally managed auto-proxy creator.
/// </summary>
public const string AUTO_PROXY_CREATOR_OBJECT_NAME =
"Spring.Aop.Config.InternalAutoProxyCreator";
/// <summary>
/// Registers the auto proxy creator if necessary.
/// </summary>
/// <param name="parserContext">The parser context.</param>
/// <param name="sourceElement">The source element.</param>
public static void RegisterAutoProxyCreatorIfNecessary(ParserContext parserContext, XmlElement sourceElement)
{
RegisterApcAsRequired(typeof(DefaultAdvisorAutoProxyCreator), parserContext);
}
/// <summary>
/// Registries the or escalate apc as required.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="parserContext">The parser context.</param>
private static void RegisterApcAsRequired(Type type, ParserContext parserContext)
{
AssertUtils.ArgumentNotNull(parserContext, "parserContext");
IObjectDefinitionRegistry registry = parserContext.Registry;
if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(type);
//TODO source/role not yet implemented in .NET
objectDefinition.PropertyValues.Add("order", int.MaxValue);
registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
}
}
/// <summary>
/// Forces the auto proxy creator to use decorator proxy.
/// </summary>
/// <param name="registry">The registry.</param>
public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
{
if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
definition.PropertyValues.Add("ProxyTargetType", true);
}
}
}
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Xml;
using Spring.Aop.Framework.AutoProxy;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
#endregion
namespace Spring.Aop.Config
{
/// <summary>
/// Utility class for handling registration of auto-proxy creators used internally by the
/// <code>aop</code> namespace tags.
/// </summary>
/// <author>Rob Harrop</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
public class AopNamespaceUtils
{
/// <summary>
/// The object name of the internally managed auto-proxy creator.
/// </summary>
public const string AUTO_PROXY_CREATOR_OBJECT_NAME =
"Spring.Aop.Config.InternalAutoProxyCreator";
/// <summary>
/// Registers the auto proxy creator if necessary.
/// </summary>
/// <param name="parserContext">The parser context.</param>
/// <param name="sourceElement">The source element.</param>
public static void RegisterAutoProxyCreatorIfNecessary(ParserContext parserContext, XmlElement sourceElement)
{
RegisterApcAsRequired(typeof(DefaultAdvisorAutoProxyCreator), parserContext);
}
/// <summary>
/// Registries the or escalate apc as required.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="parserContext">The parser context.</param>
private static void RegisterApcAsRequired(Type type, ParserContext parserContext)
{
AssertUtils.ArgumentNotNull(parserContext, "parserContext");
IObjectDefinitionRegistry registry = parserContext.Registry;
if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
RootObjectDefinition objectDefinition = new RootObjectDefinition(type);
//TODO source/role not yet implemented in .NET
objectDefinition.PropertyValues.Add("order", int.MaxValue);
registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
}
}
/// <summary>
/// Forces the auto proxy creator to use decorator proxy.
/// </summary>
/// <param name="registry">The registry.</param>
public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
{
if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
{
IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
definition.PropertyValues.Add("ProxyTargetType", true);
}
}
}
}

View File

@@ -1,159 +1,158 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Xml;
using Spring.Aop.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
namespace Spring.Aop.Config
{
/// <summary>
/// The <see cref="IObjectDefinitionParser"/> for the <code>&lt;aop:config&gt;</code> tag.
/// </summary>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: ConfigObjectDefinitionParser.cs,v 1.3 2008/02/20 14:29:13 bbaia Exp $</version>
public class ConfigObjectDefinitionParser : IObjectDefinitionParser
{
/// <summary>
/// The '<code>proxy-target-type</code>' attribute
/// </summary>
private static readonly string PROXY_TARGET_TYPE = "proxy-target-type";
private static readonly string ID = "id";
private static readonly string ORDER_PROPERTY = "order";
private static readonly string ADVICE_REF = "advice-ref";
private static readonly string ADVICE_OBJECT_NAME = "adviceObjectName";
private static readonly string POINTCUT_REF = "pointcut-ref";
#region IObjectDefinitionParser Members
/// <summary>
/// Parse the specified XmlElement and register the resulting
/// ObjectDefinitions with the <see cref="ParserContext.Registry"/> IObjectDefinitionRegistry
/// embedded in the supplied <see cref="ParserContext"/>
/// </summary>
/// <param name="element">The element to be parsed.</param>
/// <param name="parserContext">The object encapsulating the current state of the parsing process.
/// Provides access to a IObjectDefinitionRegistry</param>
/// <returns>The primary object definition.</returns>
/// <remarks>
/// <p>
/// This method is never invoked if the parser is namespace aware
/// and was called to process the root node.
/// </p>
/// </remarks>
public IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
ConfigureAutoProxyCreator(parserContext, element);
XmlNodeList advisorNodes = element.GetElementsByTagName("advisor", element.NamespaceURI);
//XmlNodeList advisorNodes = element.SelectNodes("*[local-name()='advisor' and namespace-uri()='" + element.NamespaceURI + "']");
foreach (XmlElement advisorElement in advisorNodes)
{
ParseAdvisor(advisorElement, parserContext);
}
return null;
}
/// <summary>
/// Parses the supplied advisor element and registers the resulting <see cref="IAdvisor"/>
/// </summary>
/// <param name="advisorElement">The advisor element.</param>
/// <param name="parserContext">The parser context.</param>
private void ParseAdvisor(XmlElement advisorElement, ParserContext parserContext)
{
AbstractObjectDefinition advisorDef = CreateAdvisorObjectDefinition(advisorElement, parserContext);
string id = advisorElement.GetAttribute(ID);
string pointcutObjectName = ParsePointcutProperty(advisorElement, parserContext);
advisorDef.PropertyValues.Add(POINTCUT_REF, new RuntimeObjectReference(pointcutObjectName));
string advisorObjectName = id;
if (StringUtils.HasText(advisorObjectName))
{
parserContext.Registry.RegisterObjectDefinition(advisorObjectName, advisorDef);
}
else
{
parserContext.ReaderContext.RegisterWithGeneratedName(advisorDef);
}
}
private string ParsePointcutProperty(XmlElement element, ParserContext parserContext)
{
if (element.HasAttribute(POINTCUT_REF))
{
string pointcutRef = element.GetAttribute(POINTCUT_REF);
if (!StringUtils.HasText(pointcutRef))
{
parserContext.ReaderContext.ReportException(element, "advisor", "'pointcut-ref' attribute contains empty value.");
}
return pointcutRef;
}
else
{
parserContext.ReaderContext.ReportException(element, "advisor", "'must define 'pointcut-ref' on <advisor> tag.");
return null;
}
}
private AbstractObjectDefinition CreateAdvisorObjectDefinition(XmlElement advisorElement, ParserContext parserContext)
{
ObjectDefinitionBuilder advisorDefinitionBuilder =
parserContext.ParserHelper.CreateRootObjectDefinitionBuilder(typeof(DefaultObjectFactoryPointcutAdvisor));
if (advisorElement.HasAttribute(ORDER_PROPERTY))
{
advisorDefinitionBuilder.AddPropertyValue(ORDER_PROPERTY, advisorElement.GetAttribute(ORDER_PROPERTY));
}
advisorDefinitionBuilder.AddPropertyValue(ADVICE_OBJECT_NAME, advisorElement.GetAttribute(ADVICE_REF));
return advisorDefinitionBuilder.ObjectDefinition;
}
private static void ConfigureAutoProxyCreator(ParserContext parserContext, XmlElement element)
{
AopNamespaceUtils.RegisterAutoProxyCreatorIfNecessary(parserContext, element);
bool proxyTargetClass =
parserContext.ParserHelper.IsTrueStringValue(element.GetAttribute(PROXY_TARGET_TYPE));
if (proxyTargetClass)
{
AopNamespaceUtils.ForceAutoProxyCreatorToUseDecoratorProxy(parserContext.Registry);
}
}
#endregion
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System.Xml;
using Spring.Aop.Support;
using Spring.Objects.Factory.Config;
using Spring.Objects.Factory.Support;
using Spring.Objects.Factory.Xml;
using Spring.Util;
namespace Spring.Aop.Config
{
/// <summary>
/// The <see cref="IObjectDefinitionParser"/> for the <code>&lt;aop:config&gt;</code> tag.
/// </summary>
/// <author>Mark Pollack (.NET)</author>
public class ConfigObjectDefinitionParser : IObjectDefinitionParser
{
/// <summary>
/// The '<code>proxy-target-type</code>' attribute
/// </summary>
private static readonly string PROXY_TARGET_TYPE = "proxy-target-type";
private static readonly string ID = "id";
private static readonly string ORDER_PROPERTY = "order";
private static readonly string ADVICE_REF = "advice-ref";
private static readonly string ADVICE_OBJECT_NAME = "adviceObjectName";
private static readonly string POINTCUT_REF = "pointcut-ref";
#region IObjectDefinitionParser Members
/// <summary>
/// Parse the specified XmlElement and register the resulting
/// ObjectDefinitions with the <see cref="ParserContext.Registry"/> IObjectDefinitionRegistry
/// embedded in the supplied <see cref="ParserContext"/>
/// </summary>
/// <param name="element">The element to be parsed.</param>
/// <param name="parserContext">The object encapsulating the current state of the parsing process.
/// Provides access to a IObjectDefinitionRegistry</param>
/// <returns>The primary object definition.</returns>
/// <remarks>
/// <p>
/// This method is never invoked if the parser is namespace aware
/// and was called to process the root node.
/// </p>
/// </remarks>
public IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
{
ConfigureAutoProxyCreator(parserContext, element);
XmlNodeList advisorNodes = element.GetElementsByTagName("advisor", element.NamespaceURI);
//XmlNodeList advisorNodes = element.SelectNodes("*[local-name()='advisor' and namespace-uri()='" + element.NamespaceURI + "']");
foreach (XmlElement advisorElement in advisorNodes)
{
ParseAdvisor(advisorElement, parserContext);
}
return null;
}
/// <summary>
/// Parses the supplied advisor element and registers the resulting <see cref="IAdvisor"/>
/// </summary>
/// <param name="advisorElement">The advisor element.</param>
/// <param name="parserContext">The parser context.</param>
private void ParseAdvisor(XmlElement advisorElement, ParserContext parserContext)
{
AbstractObjectDefinition advisorDef = CreateAdvisorObjectDefinition(advisorElement, parserContext);
string id = advisorElement.GetAttribute(ID);
string pointcutObjectName = ParsePointcutProperty(advisorElement, parserContext);
advisorDef.PropertyValues.Add(POINTCUT_REF, new RuntimeObjectReference(pointcutObjectName));
string advisorObjectName = id;
if (StringUtils.HasText(advisorObjectName))
{
parserContext.Registry.RegisterObjectDefinition(advisorObjectName, advisorDef);
}
else
{
parserContext.ReaderContext.RegisterWithGeneratedName(advisorDef);
}
}
private string ParsePointcutProperty(XmlElement element, ParserContext parserContext)
{
if (element.HasAttribute(POINTCUT_REF))
{
string pointcutRef = element.GetAttribute(POINTCUT_REF);
if (!StringUtils.HasText(pointcutRef))
{
parserContext.ReaderContext.ReportException(element, "advisor", "'pointcut-ref' attribute contains empty value.");
}
return pointcutRef;
}
else
{
parserContext.ReaderContext.ReportException(element, "advisor", "'must define 'pointcut-ref' on <advisor> tag.");
return null;
}
}
private AbstractObjectDefinition CreateAdvisorObjectDefinition(XmlElement advisorElement, ParserContext parserContext)
{
ObjectDefinitionBuilder advisorDefinitionBuilder =
parserContext.ParserHelper.CreateRootObjectDefinitionBuilder(typeof(DefaultObjectFactoryPointcutAdvisor));
if (advisorElement.HasAttribute(ORDER_PROPERTY))
{
advisorDefinitionBuilder.AddPropertyValue(ORDER_PROPERTY, advisorElement.GetAttribute(ORDER_PROPERTY));
}
advisorDefinitionBuilder.AddPropertyValue(ADVICE_OBJECT_NAME, advisorElement.GetAttribute(ADVICE_REF));
return advisorDefinitionBuilder.ObjectDefinition;
}
private static void ConfigureAutoProxyCreator(ParserContext parserContext, XmlElement element)
{
AopNamespaceUtils.RegisterAutoProxyCreatorIfNecessary(parserContext, element);
bool proxyTargetClass =
parserContext.ParserHelper.IsTrueStringValue(element.GetAttribute(PROXY_TARGET_TYPE));
if (proxyTargetClass)
{
AopNamespaceUtils.ForceAutoProxyCreatorToUseDecoratorProxy(parserContext.Registry);
}
}
#endregion
}
}

View File

@@ -1,350 +1,349 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Text;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Convenience base class for <see cref="AopAlliance.Intercept.IMethodInvocation"/>
/// implementations.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint()"/>
/// method to change this behavior, so this is a useful/ base class for
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/> implementations.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Rick Evans (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: AbstractMethodInvocation.cs,v 1.8 2007/07/05 20:29:21 bbaia Exp $</version>
[Serializable]
public abstract class AbstractMethodInvocation : IMethodInvocation
{
/// <summary>
/// The arguments (if any = may be <see lang="null"/>) to the method
/// that is to be invoked.
/// </summary>
protected object[] arguments;
/// <summary>
/// The target object that the method is to be invoked on.
/// </summary>
protected object target;
/// <summary>
/// The AOP proxy for the target object.
/// </summary>
protected object proxy;
/// <summary>
/// The method invocation that is to be invoked.
/// </summary>
protected MethodInfo method;
/// <summary>
/// The list of <see cref="AopAlliance.Intercept.IMethodInterceptor"/> and
/// <cref see="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// that need dynamic checks.
/// </summary>
protected IList interceptors;
/// <summary>
/// The declaring type of the method that is to be invoked.
/// </summary>
protected Type targetType;
/// <summary>
/// The index from 0 of the current interceptor we're invoking.
/// </summary>
protected int currentInterceptorIndex;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such exposes no publicly visible
/// constructors.
/// </p>
/// <p>
/// <note type="implementnotes">
/// The <paramref name="interceptors"/> list can also contain any
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>s
/// that need evaluation at runtime.
/// <see cref="Spring.Aop.IMethodMatcher"/>s included in an
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// must already have been found to have matched as far as was possible
/// <b>statically</b>. Passing an array might be about 10% faster, but
/// would complicate the code, and it would work only for static
/// pointcuts.
/// </note>
/// </p>
/// </remarks>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">the target method.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the <paramref name="target"/> is <see lang="null"/>.
/// </exception>
protected AbstractMethodInvocation(object proxy, object target,
MethodInfo method, object[] arguments, Type targetType, IList interceptors)
{
#region Sanity Check
AssertUtils.ArgumentNotNull(target, "target");
AssertUtils.ArgumentNotNull(method, "method");
#endregion
this.proxy = proxy;
this.target = target;
this.method = method;
this.targetType = targetType;
this.arguments = arguments;
this.interceptors = interceptors;
}
/// <summary>
/// Gets the method invocation that is to be invoked.
/// </summary>
/// <remarks>
/// <p>
/// May or may not correspond with a method invoked on an underlying
/// implementation of that interface.
/// </p>
/// </remarks>
/// <see cref="AopAlliance.Intercept.IMethodInvocation.Method"/>
public virtual MethodInfo Method
{
get { return method; }
}
/// <summary>
/// Gets the static part of this joinpoint.
/// </summary>
/// <value>
/// The proxied member's information.
/// </value>
/// <see cref="AopAlliance.Intercept.IJoinpoint.StaticPart"/>
public virtual MemberInfo StaticPart
{
get { return Method; }
}
/// <summary>
/// Gets the proxy that this interception was made through.
/// </summary>
/// <value>
/// The proxy that this interception was made through.
/// </value>
public virtual object Proxy
{
get { return this.proxy; }
}
/// <summary>
/// Gets the target object for the invocation.
/// </summary>
/// <value>
/// The target object for this method invocation.
/// </value>
public virtual object Target
{
get { return this.target; }
}
/// <summary>
/// Gets the type of the target object.
/// </summary>
/// <value>
/// The type of the target object.
/// </value>
public virtual Type TargetType
{
get { return this.targetType; }
}
/// <summary>
/// Gets and sets the arguments (if any - may be <cref lang="null"/>)
/// to the method that is to be invoked.
/// </summary>
/// <value>
/// The arguments (if any - may be <cref lang="null"/>) to the
/// method that is to be invoked.
/// </value>
/// <see cref="AopAlliance.Intercept.IInvocation.Arguments"/>
public virtual object[] Arguments
{
get { return this.arguments; }
set { this.arguments = value; }
}
/// <summary>
/// The list of method interceptors.
/// </summary>
/// <remarks>
/// <p>
/// May be <see lang="null"/>.
/// </p>
/// </remarks>
public virtual IList Interceptors
{
get { return this.interceptors; }
set { this.interceptors = value; }
}
/// <summary>
/// Gets the target object.
/// </summary>
public virtual object This
{
get { return this.target; }
}
/// <summary>
/// Proceeds to the next interceptor in the chain.
/// </summary>
/// <returns>
/// The return value of the method invocation.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors at the joinpoint throws an exception.
/// </exception>
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/>
public virtual object Proceed()
{
if (this.interceptors == null ||
this.currentInterceptorIndex == this.interceptors.Count)
{
return InvokeJoinpoint();
}
object interceptor = this.interceptors[this.currentInterceptorIndex];
InterceptorAndDynamicMethodMatcher dynamicMatcher
= interceptor as InterceptorAndDynamicMethodMatcher;
IMethodInvocation nextInvocation = PrepareMethodInvocationForProceed(this);
if (dynamicMatcher != null)
{
// evaluate dynamic method matcher here: static part will already have
// been evaluated and found to match...
if (dynamicMatcher.MethodMatcher.Matches(
nextInvocation.Method, nextInvocation.TargetType, nextInvocation.Arguments))
{
return dynamicMatcher.Interceptor.Invoke(nextInvocation);
}
else
{
// dynamic match failed; skip this interceptor and invoke the next in the chain...
return nextInvocation.Proceed();
}
}
else
{
// it's an interceptor so we just invoke it: the pointcut will have
// been evaluated statically before this object was constructed...
return ((IMethodInterceptor)interceptor).Invoke(nextInvocation);
}
}
/// <summary>
/// Retrieves a new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance
/// for the next Proceed method call.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation.PrepareMethodInvocationForProceed"/>
protected abstract IMethodInvocation PrepareMethodInvocationForProceed(
IMethodInvocation invocation);
/// <summary>
/// Invokes the joinpoint.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation.InvokeJoinpoint"/>
protected abstract object InvokeJoinpoint();
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// invocation.
/// </summary>
/// <remarks>
/// <p>
/// <note type="implementnotes">
/// Does <b>not</b> invoke <see cref="System.Object.ToString()"/> on the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.This"/> target
/// object, as that too may be proxied.
/// </note>
/// </p>
/// </remarks>
/// <returns>
/// A <see cref="System.String"/> that represents the current invocation.
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder("Invocation: method '");
buffer.Append(Method.Name).Append("', ").Append("arguments ");
buffer.Append(this.arguments != null ? StringUtils.ArrayToCommaDelimitedString(this.arguments) : "[none]");
buffer.Append("; ");
if (this.target == null)
{
buffer.Append("target is null.");
}
else
{
buffer.Append("target is of Type [").Append(this.targetType.FullName).Append(']');
}
return buffer.ToString();
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Text;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Convenience base class for <see cref="AopAlliance.Intercept.IMethodInvocation"/>
/// implementations.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint()"/>
/// method to change this behavior, so this is a useful/ base class for
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/> implementations.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Rick Evans (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
[Serializable]
public abstract class AbstractMethodInvocation : IMethodInvocation
{
/// <summary>
/// The arguments (if any = may be <see lang="null"/>) to the method
/// that is to be invoked.
/// </summary>
protected object[] arguments;
/// <summary>
/// The target object that the method is to be invoked on.
/// </summary>
protected object target;
/// <summary>
/// The AOP proxy for the target object.
/// </summary>
protected object proxy;
/// <summary>
/// The method invocation that is to be invoked.
/// </summary>
protected MethodInfo method;
/// <summary>
/// The list of <see cref="AopAlliance.Intercept.IMethodInterceptor"/> and
/// <cref see="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// that need dynamic checks.
/// </summary>
protected IList interceptors;
/// <summary>
/// The declaring type of the method that is to be invoked.
/// </summary>
protected Type targetType;
/// <summary>
/// The index from 0 of the current interceptor we're invoking.
/// </summary>
protected int currentInterceptorIndex;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such exposes no publicly visible
/// constructors.
/// </p>
/// <p>
/// <note type="implementnotes">
/// The <paramref name="interceptors"/> list can also contain any
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>s
/// that need evaluation at runtime.
/// <see cref="Spring.Aop.IMethodMatcher"/>s included in an
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// must already have been found to have matched as far as was possible
/// <b>statically</b>. Passing an array might be about 10% faster, but
/// would complicate the code, and it would work only for static
/// pointcuts.
/// </note>
/// </p>
/// </remarks>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">the target method.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the <paramref name="target"/> is <see lang="null"/>.
/// </exception>
protected AbstractMethodInvocation(object proxy, object target,
MethodInfo method, object[] arguments, Type targetType, IList interceptors)
{
#region Sanity Check
AssertUtils.ArgumentNotNull(target, "target");
AssertUtils.ArgumentNotNull(method, "method");
#endregion
this.proxy = proxy;
this.target = target;
this.method = method;
this.targetType = targetType;
this.arguments = arguments;
this.interceptors = interceptors;
}
/// <summary>
/// Gets the method invocation that is to be invoked.
/// </summary>
/// <remarks>
/// <p>
/// May or may not correspond with a method invoked on an underlying
/// implementation of that interface.
/// </p>
/// </remarks>
/// <see cref="AopAlliance.Intercept.IMethodInvocation.Method"/>
public virtual MethodInfo Method
{
get { return method; }
}
/// <summary>
/// Gets the static part of this joinpoint.
/// </summary>
/// <value>
/// The proxied member's information.
/// </value>
/// <see cref="AopAlliance.Intercept.IJoinpoint.StaticPart"/>
public virtual MemberInfo StaticPart
{
get { return Method; }
}
/// <summary>
/// Gets the proxy that this interception was made through.
/// </summary>
/// <value>
/// The proxy that this interception was made through.
/// </value>
public virtual object Proxy
{
get { return this.proxy; }
}
/// <summary>
/// Gets the target object for the invocation.
/// </summary>
/// <value>
/// The target object for this method invocation.
/// </value>
public virtual object Target
{
get { return this.target; }
}
/// <summary>
/// Gets the type of the target object.
/// </summary>
/// <value>
/// The type of the target object.
/// </value>
public virtual Type TargetType
{
get { return this.targetType; }
}
/// <summary>
/// Gets and sets the arguments (if any - may be <cref lang="null"/>)
/// to the method that is to be invoked.
/// </summary>
/// <value>
/// The arguments (if any - may be <cref lang="null"/>) to the
/// method that is to be invoked.
/// </value>
/// <see cref="AopAlliance.Intercept.IInvocation.Arguments"/>
public virtual object[] Arguments
{
get { return this.arguments; }
set { this.arguments = value; }
}
/// <summary>
/// The list of method interceptors.
/// </summary>
/// <remarks>
/// <p>
/// May be <see lang="null"/>.
/// </p>
/// </remarks>
public virtual IList Interceptors
{
get { return this.interceptors; }
set { this.interceptors = value; }
}
/// <summary>
/// Gets the target object.
/// </summary>
public virtual object This
{
get { return this.target; }
}
/// <summary>
/// Proceeds to the next interceptor in the chain.
/// </summary>
/// <returns>
/// The return value of the method invocation.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors at the joinpoint throws an exception.
/// </exception>
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/>
public virtual object Proceed()
{
if (this.interceptors == null ||
this.currentInterceptorIndex == this.interceptors.Count)
{
return InvokeJoinpoint();
}
object interceptor = this.interceptors[this.currentInterceptorIndex];
InterceptorAndDynamicMethodMatcher dynamicMatcher
= interceptor as InterceptorAndDynamicMethodMatcher;
IMethodInvocation nextInvocation = PrepareMethodInvocationForProceed(this);
if (dynamicMatcher != null)
{
// evaluate dynamic method matcher here: static part will already have
// been evaluated and found to match...
if (dynamicMatcher.MethodMatcher.Matches(
nextInvocation.Method, nextInvocation.TargetType, nextInvocation.Arguments))
{
return dynamicMatcher.Interceptor.Invoke(nextInvocation);
}
else
{
// dynamic match failed; skip this interceptor and invoke the next in the chain...
return nextInvocation.Proceed();
}
}
else
{
// it's an interceptor so we just invoke it: the pointcut will have
// been evaluated statically before this object was constructed...
return ((IMethodInterceptor)interceptor).Invoke(nextInvocation);
}
}
/// <summary>
/// Retrieves a new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance
/// for the next Proceed method call.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation.PrepareMethodInvocationForProceed"/>
protected abstract IMethodInvocation PrepareMethodInvocationForProceed(
IMethodInvocation invocation);
/// <summary>
/// Invokes the joinpoint.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation.InvokeJoinpoint"/>
protected abstract object InvokeJoinpoint();
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// invocation.
/// </summary>
/// <remarks>
/// <p>
/// <note type="implementnotes">
/// Does <b>not</b> invoke <see cref="System.Object.ToString()"/> on the
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.This"/> target
/// object, as that too may be proxied.
/// </note>
/// </p>
/// </remarks>
/// <returns>
/// A <see cref="System.String"/> that represents the current invocation.
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder("Invocation: method '");
buffer.Append(Method.Name).Append("', ").Append("arguments ");
buffer.Append(this.arguments != null ? StringUtils.ArrayToCommaDelimitedString(this.arguments) : "[none]");
buffer.Append("; ");
if (this.target == null)
{
buffer.Append("target is null.");
}
else
{
buffer.Append("target is of Type [").Append(this.targetType.FullName).Append(']');
}
return buffer.ToString();
}
}
}

View File

@@ -1,110 +1,109 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/> implementation
/// that registers instances of any non-default
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances with the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/>
/// singleton.
/// </summary>
/// <remarks>
/// <p>
/// The only requirement for it to work is that it needs to be defined
/// in an application context along with any arbitrary "non-native" Spring.NET
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances that need
/// to be recognized by Spring.NET's AOP framework.
/// </p>
/// </remarks>
/// <author>Dmitriy Kopylenko</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AdvisorAdapterRegistrationManager.cs,v 1.5 2007/08/22 08:49:08 markpollack Exp $</version>
public class AdvisorAdapterRegistrationManager : IObjectPostProcessor
{
/// <summary>
/// Apply this <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/>
/// to the given new object instance <i>before</i> any object initialization callbacks.
/// </summary>
/// <remarks>
/// <p>
/// Does nothing, simply returns the supplied <paramref name="instance"/> as is.
/// </p>
/// </remarks>
/// <param name="instance">
/// The new object instance.
/// </param>
/// <param name="name">
/// The name of the object.
/// </param>
/// <returns>
/// The object instance to use, either the original or a wrapped one.
/// </returns>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of errors.
/// </exception>
public virtual object PostProcessBeforeInitialization(object instance, string name)
{
return instance;
}
/// <summary>
/// Apply this <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/> to the
/// given new object instance <i>after</i> any object initialization callbacks.
/// </summary>
/// <remarks>
/// <p>
/// Registers the supplied <paramref name="instance"/> with the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/>
/// singleton if it is an <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>
/// instance.
/// </p>
/// </remarks>
/// <param name="instance">
/// The new object instance.
/// </param>
/// <param name="objectName">
/// The name of the object.
/// </param>
/// <returns>
/// The object instance to use, either the original or a wrapped one.
/// </returns>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of errors.
/// </exception>
public virtual object PostProcessAfterInitialization(object instance, string objectName)
{
IAdvisorAdapter adapter = instance as IAdvisorAdapter;
if (adapter != null)
{
GlobalAdvisorAdapterRegistry.Instance.RegisterAdvisorAdapter(adapter);
}
return instance;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/> implementation
/// that registers instances of any non-default
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances with the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/>
/// singleton.
/// </summary>
/// <remarks>
/// <p>
/// The only requirement for it to work is that it needs to be defined
/// in an application context along with any arbitrary "non-native" Spring.NET
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances that need
/// to be recognized by Spring.NET's AOP framework.
/// </p>
/// </remarks>
/// <author>Dmitriy Kopylenko</author>
/// <author>Aleksandar Seovic (.NET)</author>
public class AdvisorAdapterRegistrationManager : IObjectPostProcessor
{
/// <summary>
/// Apply this <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/>
/// to the given new object instance <i>before</i> any object initialization callbacks.
/// </summary>
/// <remarks>
/// <p>
/// Does nothing, simply returns the supplied <paramref name="instance"/> as is.
/// </p>
/// </remarks>
/// <param name="instance">
/// The new object instance.
/// </param>
/// <param name="name">
/// The name of the object.
/// </param>
/// <returns>
/// The object instance to use, either the original or a wrapped one.
/// </returns>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of errors.
/// </exception>
public virtual object PostProcessBeforeInitialization(object instance, string name)
{
return instance;
}
/// <summary>
/// Apply this <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/> to the
/// given new object instance <i>after</i> any object initialization callbacks.
/// </summary>
/// <remarks>
/// <p>
/// Registers the supplied <paramref name="instance"/> with the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/>
/// singleton if it is an <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>
/// instance.
/// </p>
/// </remarks>
/// <param name="instance">
/// The new object instance.
/// </param>
/// <param name="objectName">
/// The name of the object.
/// </param>
/// <returns>
/// The object instance to use, either the original or a wrapped one.
/// </returns>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of errors.
/// </exception>
public virtual object PostProcessAfterInitialization(object instance, string objectName)
{
IAdvisorAdapter adapter = instance as IAdvisorAdapter;
if (adapter != null)
{
GlobalAdvisorAdapterRegistry.Instance.RegisterAdvisorAdapter(adapter);
}
return instance;
}
}
}

View File

@@ -1,81 +1,80 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IAfterReturningAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AfterReturningAdviceAdapter.cs,v 1.5 2007/03/16 04:01:20 aseovic Exp $</version>
[Serializable]
internal class AfterReturningAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IAfterReturningAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IAfterReturningAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IAfterReturningAdvice;
}
/// <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);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IAfterReturningAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
internal class AfterReturningAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IAfterReturningAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IAfterReturningAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IAfterReturningAdvice;
}
/// <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);
}
}
}

View File

@@ -1,97 +1,96 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Interceptor to wrap an <see cref="Spring.Aop.IAfterReturningAdvice"/>
/// instance.
/// </summary>
/// <remarks>
/// <p>
/// A more efficient alternative solution in cases where there is no
/// interception advice and therefore no need to create an
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/> object may be
/// offered in future.
/// </p>
/// <p>
/// Used internally by the AOP framework: application developers should not need
/// to use this class directly.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AfterReturningAdviceInterceptor.cs,v 1.8 2007/03/16 04:01:21 aseovic Exp $</version>
[Serializable]
public sealed class AfterReturningAdviceInterceptor : IMethodInterceptor
{
private IAfterReturningAdvice advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
/// class.
/// </summary>
/// <param name="advice">
/// The advice to be applied after a target method successfully
/// returns.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.advice = advice;
}
/// <summary>
/// Executes interceptor after the target method successfully returns.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/>; this return value may
/// well have been intercepted by the interceptor.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
public object Invoke(IMethodInvocation invocation)
{
object returnValue = invocation.Proceed();
advice.AfterReturning(
returnValue, invocation.Method, invocation.Arguments, invocation.This);
return returnValue;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Interceptor to wrap an <see cref="Spring.Aop.IAfterReturningAdvice"/>
/// instance.
/// </summary>
/// <remarks>
/// <p>
/// A more efficient alternative solution in cases where there is no
/// interception advice and therefore no need to create an
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/> object may be
/// offered in future.
/// </p>
/// <p>
/// Used internally by the AOP framework: application developers should not need
/// to use this class directly.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public sealed class AfterReturningAdviceInterceptor : IMethodInterceptor
{
private IAfterReturningAdvice advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
/// class.
/// </summary>
/// <param name="advice">
/// The advice to be applied after a target method successfully
/// returns.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.advice = advice;
}
/// <summary>
/// Executes interceptor after the target method successfully returns.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/>; this return value may
/// well have been intercepted by the interceptor.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
public object Invoke(IMethodInvocation invocation)
{
object returnValue = invocation.Proceed();
advice.AfterReturning(
returnValue, invocation.Method, invocation.Arguments, invocation.This);
return returnValue;
}
}
}

View File

@@ -1,81 +1,80 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IMethodBeforeAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: BeforeAdviceAdapter.cs,v 1.4 2007/03/16 04:01:21 aseovic Exp $</version>
[Serializable]
internal class BeforeAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IMethodBeforeAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IMethodBeforeAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IMethodBeforeAdvice;
}
/// <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);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IMethodBeforeAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
internal class BeforeAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IMethodBeforeAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IMethodBeforeAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IMethodBeforeAdvice;
}
/// <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);
}
}
}

View File

@@ -1,156 +1,155 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using Spring.Aop;
using Spring.Aop.Support;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Default implementation of the
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry"/>
/// interface.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DefaultAdvisorAdapterRegistry.cs,v 1.5 2006/04/09 07:18:35 markpollack Exp $</version>
public class DefaultAdvisorAdapterRegistry : IAdvisorAdapterRegistry
{
private IList adapters = new ArrayList();
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.DefaultAdvisorAdapterRegistry"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This constructor will also register the well-known
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> types.
/// </p>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>
public DefaultAdvisorAdapterRegistry()
{
// register well-known adapters...
RegisterAdvisorAdapter(new BeforeAdviceAdapter());
RegisterAdvisorAdapter(new AfterReturningAdviceAdapter());
RegisterAdvisorAdapter(new ThrowsAdviceAdapter());
}
/// <summary>
/// Returns an <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>.
/// </summary>
/// <param name="advice">
/// The object that should be an advice, such as
/// <see cref="Spring.Aop.IBeforeAdvice"/> or
/// <see cref="Spring.Aop.IThrowsAdvice"/>.
/// </param>
/// <returns>
/// An <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>. Never returns <cref lang="null"/>. If
/// the <paramref name="advice"/> parameter is an
/// <see cref="Spring.Aop.IAdvisor"/>, it will simply be returned.
/// </returns>
/// <exception cref="UnknownAdviceTypeException">
/// If no registered
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> can wrap
/// the supplied <paramref name="advice"/>.
/// </exception>
public virtual IAdvisor Wrap(object advice)
{
if (advice is IAdvisor)
{
return (IAdvisor) advice;
}
if (!(advice is IAdvice))
{
throw new UnknownAdviceTypeException(advice);
}
IAdvice adviceObject = (IAdvice) advice;
if (adviceObject is IInterceptor)
{
// so well-known it doesn't even need an adapter...
return new DefaultPointcutAdvisor(adviceObject);
}
foreach (IAdvisorAdapter adapter in this.adapters)
{
// check that it is supported...
if (adapter.SupportsAdvice(adviceObject))
{
return new DefaultPointcutAdvisor(adviceObject);
}
}
throw new UnknownAdviceTypeException(advice);
}
/// <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);
}
/// <summary>
/// Register the given <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>.
/// </summary>
/// <param name="adapter">
/// An <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> that
/// understands the particular advisor and advice types.
/// </param>
public virtual void RegisterAdvisorAdapter(IAdvisorAdapter adapter)
{
this.adapters.Add(adapter);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using Spring.Aop;
using Spring.Aop.Support;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Default implementation of the
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry"/>
/// interface.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public class DefaultAdvisorAdapterRegistry : IAdvisorAdapterRegistry
{
private IList adapters = new ArrayList();
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.DefaultAdvisorAdapterRegistry"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This constructor will also register the well-known
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> types.
/// </p>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>
public DefaultAdvisorAdapterRegistry()
{
// register well-known adapters...
RegisterAdvisorAdapter(new BeforeAdviceAdapter());
RegisterAdvisorAdapter(new AfterReturningAdviceAdapter());
RegisterAdvisorAdapter(new ThrowsAdviceAdapter());
}
/// <summary>
/// Returns an <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>.
/// </summary>
/// <param name="advice">
/// The object that should be an advice, such as
/// <see cref="Spring.Aop.IBeforeAdvice"/> or
/// <see cref="Spring.Aop.IThrowsAdvice"/>.
/// </param>
/// <returns>
/// An <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>. Never returns <cref lang="null"/>. If
/// the <paramref name="advice"/> parameter is an
/// <see cref="Spring.Aop.IAdvisor"/>, it will simply be returned.
/// </returns>
/// <exception cref="UnknownAdviceTypeException">
/// If no registered
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> can wrap
/// the supplied <paramref name="advice"/>.
/// </exception>
public virtual IAdvisor Wrap(object advice)
{
if (advice is IAdvisor)
{
return (IAdvisor) advice;
}
if (!(advice is IAdvice))
{
throw new UnknownAdviceTypeException(advice);
}
IAdvice adviceObject = (IAdvice) advice;
if (adviceObject is IInterceptor)
{
// so well-known it doesn't even need an adapter...
return new DefaultPointcutAdvisor(adviceObject);
}
foreach (IAdvisorAdapter adapter in this.adapters)
{
// check that it is supported...
if (adapter.SupportsAdvice(adviceObject))
{
return new DefaultPointcutAdvisor(adviceObject);
}
}
throw new UnknownAdviceTypeException(advice);
}
/// <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);
}
/// <summary>
/// Register the given <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>.
/// </summary>
/// <param name="adapter">
/// An <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> that
/// understands the particular advisor and advice types.
/// </param>
public virtual void RegisterAdvisorAdapter(IAdvisorAdapter adapter)
{
this.adapters.Add(adapter);
}
}
}

View File

@@ -1,67 +1,66 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Provides Singleton-style access to the default
/// <see cref="IAdvisorAdapterRegistry"/> instance.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: GlobalAdvisorAdapterRegistry.cs,v 1.5 2006/04/09 07:18:35 markpollack Exp $</version>
public sealed class GlobalAdvisorAdapterRegistry : DefaultAdvisorAdapterRegistry
{
private static readonly GlobalAdvisorAdapterRegistry instance
= new GlobalAdvisorAdapterRegistry();
/// <summary>
/// The default <see cref="IAdvisorAdapterRegistry"/> instance.
/// </summary>
public static GlobalAdvisorAdapterRegistry Instance
{
get { return instance; }
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This contructor is marked as <see langword="private"/> to enforce the
/// Singleton pattern
/// </p>
/// </remarks>
private GlobalAdvisorAdapterRegistry()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Provides Singleton-style access to the default
/// <see cref="IAdvisorAdapterRegistry"/> instance.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class GlobalAdvisorAdapterRegistry : DefaultAdvisorAdapterRegistry
{
private static readonly GlobalAdvisorAdapterRegistry instance
= new GlobalAdvisorAdapterRegistry();
/// <summary>
/// The default <see cref="IAdvisorAdapterRegistry"/> instance.
/// </summary>
public static GlobalAdvisorAdapterRegistry Instance
{
get { return instance; }
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.GlobalAdvisorAdapterRegistry"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This contructor is marked as <see langword="private"/> to enforce the
/// Singleton pattern
/// </p>
/// </remarks>
private GlobalAdvisorAdapterRegistry()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,100 +1,99 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Permits the handling of new advisors and advice types as extensions to
/// the Spring AOP framework.
/// </summary>
/// <remarks>
/// <p>
/// Implementors can create AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/>s from custom advice
/// types, enabling these advice types to be used in the Spring.NET AOP
/// framework, which uses interception under the covers.
/// </p>
/// <p>
/// There is no need for most Spring.NET users to implement this interface;
/// do so only if you need to introduce more
/// <see cref="Spring.Aop.IAdvisor"/> or <see cref="AopAlliance.Aop.IAdvice"/>
/// types to Spring.NET.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvisorAdapter.cs,v 1.4 2006/04/09 07:18:35 markpollack Exp $</version>
public interface IAdvisorAdapter
{
/// <summary>
/// Does this adapter understand the supplied <paramref name="advice"/>?
/// </summary>
/// <remarks>
/// <p>
/// Is it valid to invoke the
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry.Wrap"/>
/// method with the given advice as an argument?
/// </p>
/// </remarks>
/// <param name="advice">
/// <see cref="AopAlliance.Aop.IAdvice"/> such as
/// <see cref="Spring.Aop.IBeforeAdvice"/>.
/// </param>
/// <returns><see langword="true"/> if this adapter understands the
/// supplied <paramref name="advice"/>.
/// </returns>
bool SupportsAdvice(IAdvice advice);
/// <summary>
/// Return an AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/> exposing the
/// behaviour of the given advice to an interception-based AOP
/// framework.
/// </summary>
/// <remarks>
/// <p>
/// Don't worry about any <see cref="Spring.Aop.IPointcut"/>
/// contained in the supplied <see cref="Spring.Aop.IAdvisor"/>;
/// the AOP framework will take care of checking the pointcut.
/// </p>
/// </remarks>
/// <param name="advisor">
/// The advice. The
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter.SupportsAdvice"/>
/// method must have previously returned <see langword="true"/> on the
/// supplied <paramref name="advisor"/>.
/// </param>
/// <returns>
/// An AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/> exposing the
/// behaviour of the given advice to an interception-based AOP
/// framework.
/// </returns>
IInterceptor GetInterceptor(IAdvisor advisor);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Permits the handling of new advisors and advice types as extensions to
/// the Spring AOP framework.
/// </summary>
/// <remarks>
/// <p>
/// Implementors can create AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/>s from custom advice
/// types, enabling these advice types to be used in the Spring.NET AOP
/// framework, which uses interception under the covers.
/// </p>
/// <p>
/// There is no need for most Spring.NET users to implement this interface;
/// do so only if you need to introduce more
/// <see cref="Spring.Aop.IAdvisor"/> or <see cref="AopAlliance.Aop.IAdvice"/>
/// types to Spring.NET.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAdvisorAdapter
{
/// <summary>
/// Does this adapter understand the supplied <paramref name="advice"/>?
/// </summary>
/// <remarks>
/// <p>
/// Is it valid to invoke the
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry.Wrap"/>
/// method with the given advice as an argument?
/// </p>
/// </remarks>
/// <param name="advice">
/// <see cref="AopAlliance.Aop.IAdvice"/> such as
/// <see cref="Spring.Aop.IBeforeAdvice"/>.
/// </param>
/// <returns><see langword="true"/> if this adapter understands the
/// supplied <paramref name="advice"/>.
/// </returns>
bool SupportsAdvice(IAdvice advice);
/// <summary>
/// Return an AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/> exposing the
/// behaviour of the given advice to an interception-based AOP
/// framework.
/// </summary>
/// <remarks>
/// <p>
/// Don't worry about any <see cref="Spring.Aop.IPointcut"/>
/// contained in the supplied <see cref="Spring.Aop.IAdvisor"/>;
/// the AOP framework will take care of checking the pointcut.
/// </p>
/// </remarks>
/// <param name="advisor">
/// The advice. The
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter.SupportsAdvice"/>
/// method must have previously returned <see langword="true"/> on the
/// supplied <paramref name="advisor"/>.
/// </param>
/// <returns>
/// An AOP Alliance
/// <see cref="AopAlliance.Intercept.IInterceptor"/> exposing the
/// behaviour of the given advice to an interception-based AOP
/// framework.
/// </returns>
IInterceptor GetInterceptor(IAdvisor advisor);
}
}

View File

@@ -1,114 +1,113 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// A registry of
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances.
/// </summary>
/// <remarks>
/// <p>
/// Implementations <b>must</b> also automatically register adapters for
/// <see cref="AopAlliance.Intercept.IInterceptor"/> types.
/// </p>
/// <note>
/// This is an SPI interface, that should not need to be implemented by any
/// Spring.NET user.
/// </note>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvisorAdapterRegistry.cs,v 1.3 2006/04/09 07:18:35 markpollack Exp $</version>
public interface IAdvisorAdapterRegistry
{
/// <summary>
/// Returns an <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>.
/// </summary>
/// <param name="advice">
/// The object that should be an advice, such as
/// <see cref="Spring.Aop.IBeforeAdvice"/> or
/// <see cref="Spring.Aop.IThrowsAdvice"/>.
/// </param>
/// <returns>
/// An <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>. Never returns <cref lang="null"/>. If
/// the <paramref name="advice"/> parameter is an
/// <see cref="Spring.Aop.IAdvisor"/>, it will simply be returned.
/// </returns>
/// <exception cref="UnknownAdviceTypeException">
/// If no registered
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> can wrap
/// the supplied <paramref name="advice"/>.
/// </exception>
IAdvisor Wrap(object advice);
/// <summary>
/// Returns an <see cref="AopAlliance.Intercept.IInterceptor"/> to
/// allow the use of the supplied <paramref name="advisor"/> in an
/// interception-based framework.
/// </summary>
/// <remarks>
/// <p>
/// Don't worry about the pointcut associated with the
/// <see cref="Spring.Aop.IAdvisor"/>; if it's an
/// <see cref="Spring.Aop.IPointcutAdvisor"/>, just return an
/// interceptor.
/// </p>
/// </remarks>
/// <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>
IInterceptor GetInterceptor(IAdvisor advisor);
/// <summary>
/// Register the given <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>.
/// </summary>
/// <remarks>
/// <p>
/// Note that it is not necessary to register adapters for
/// <see cref="AopAlliance.Intercept.IInterceptor"/> instances: these
/// must be automatically recognized by an
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry"/>
/// implementation.
/// </p>
/// </remarks>
/// <param name="adapter">
/// An <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> that
/// understands the particular advisor and advice types.
/// </param>
void RegisterAdvisorAdapter(IAdvisorAdapter adapter);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// A registry of
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> instances.
/// </summary>
/// <remarks>
/// <p>
/// Implementations <b>must</b> also automatically register adapters for
/// <see cref="AopAlliance.Intercept.IInterceptor"/> types.
/// </p>
/// <note>
/// This is an SPI interface, that should not need to be implemented by any
/// Spring.NET user.
/// </note>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAdvisorAdapterRegistry
{
/// <summary>
/// Returns an <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>.
/// </summary>
/// <param name="advice">
/// The object that should be an advice, such as
/// <see cref="Spring.Aop.IBeforeAdvice"/> or
/// <see cref="Spring.Aop.IThrowsAdvice"/>.
/// </param>
/// <returns>
/// An <see cref="Spring.Aop.IAdvisor"/> wrapping the supplied
/// <paramref name="advice"/>. Never returns <cref lang="null"/>. If
/// the <paramref name="advice"/> parameter is an
/// <see cref="Spring.Aop.IAdvisor"/>, it will simply be returned.
/// </returns>
/// <exception cref="UnknownAdviceTypeException">
/// If no registered
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> can wrap
/// the supplied <paramref name="advice"/>.
/// </exception>
IAdvisor Wrap(object advice);
/// <summary>
/// Returns an <see cref="AopAlliance.Intercept.IInterceptor"/> to
/// allow the use of the supplied <paramref name="advisor"/> in an
/// interception-based framework.
/// </summary>
/// <remarks>
/// <p>
/// Don't worry about the pointcut associated with the
/// <see cref="Spring.Aop.IAdvisor"/>; if it's an
/// <see cref="Spring.Aop.IPointcutAdvisor"/>, just return an
/// interceptor.
/// </p>
/// </remarks>
/// <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>
IInterceptor GetInterceptor(IAdvisor advisor);
/// <summary>
/// Register the given <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>.
/// </summary>
/// <remarks>
/// <p>
/// Note that it is not necessary to register adapters for
/// <see cref="AopAlliance.Intercept.IInterceptor"/> instances: these
/// must be automatically recognized by an
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapterRegistry"/>
/// implementation.
/// </p>
/// </remarks>
/// <param name="adapter">
/// An <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> that
/// understands the particular advisor and advice types.
/// </param>
void RegisterAdvisorAdapter(IAdvisorAdapter adapter);
}
}

View File

@@ -1,93 +1,92 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="AopAlliance.Intercept.IInterceptor"/> implementation that
/// wraps <see cref="Spring.Aop.IMethodBeforeAdvice"/> instances.
/// </summary>
/// <remarks>
/// <p>
/// In the future Spring.NET may also offer a more efficient alternative
/// solution in cases where there is no interception advice and therefore
/// no need to create an <see cref="AopAlliance.Intercept.IMethodInvocation"/>
/// object.
/// </p>
/// <p>
/// Used internally by the Spring.NET AOP framework: application developers
/// should not need to use this class directly.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: MethodBeforeAdviceInterceptor.cs,v 1.5 2007/03/16 04:01:21 aseovic Exp $</version>
[Serializable]
internal sealed class MethodBeforeAdviceInterceptor : IMethodInterceptor
{
private IMethodBeforeAdvice advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.MethodBeforeAdviceInterceptor"/>
/// class.
/// </summary>
/// <param name="advice">
/// The <see cref="Spring.Aop.IMethodBeforeAdvice"/> that is to be wrapped.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
public MethodBeforeAdviceInterceptor(IMethodBeforeAdvice advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.advice = advice;
}
/// <summary>
/// Executes interceptor before the target method successfully returns.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/>.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
public object Invoke(IMethodInvocation invocation)
{
advice.Before(invocation.Method, invocation.Arguments, invocation.This);
return invocation.Proceed();
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="AopAlliance.Intercept.IInterceptor"/> implementation that
/// wraps <see cref="Spring.Aop.IMethodBeforeAdvice"/> instances.
/// </summary>
/// <remarks>
/// <p>
/// In the future Spring.NET may also offer a more efficient alternative
/// solution in cases where there is no interception advice and therefore
/// no need to create an <see cref="AopAlliance.Intercept.IMethodInvocation"/>
/// object.
/// </p>
/// <p>
/// Used internally by the Spring.NET AOP framework: application developers
/// should not need to use this class directly.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
internal sealed class MethodBeforeAdviceInterceptor : IMethodInterceptor
{
private IMethodBeforeAdvice advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.MethodBeforeAdviceInterceptor"/>
/// class.
/// </summary>
/// <param name="advice">
/// The <see cref="Spring.Aop.IMethodBeforeAdvice"/> that is to be wrapped.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
public MethodBeforeAdviceInterceptor(IMethodBeforeAdvice advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.advice = advice;
}
/// <summary>
/// Executes interceptor before the target method successfully returns.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/>.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
public object Invoke(IMethodInvocation invocation)
{
advice.Before(invocation.Method, invocation.Arguments, invocation.This);
return invocation.Proceed();
}
}
}

View File

@@ -1,80 +1,79 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IThrowsAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ThrowsAdviceAdapter.cs,v 1.4 2007/03/16 04:01:21 aseovic Exp $</version>
[Serializable]
internal class ThrowsAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IThrowsAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IThrowsAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IThrowsAdvice;
}
/// <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);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/> implementation
/// to enable <see cref="Spring.Aop.IThrowsAdvice"/> to be used in the
/// Spring.NET AOP framework.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
internal class ThrowsAdviceAdapter : IAdvisorAdapter
{
/// <summary>
/// Returns <see langword="true"/> if the supplied
/// <paramref name="advice"/> is an instance of the
/// <see cref="Spring.Aop.IThrowsAdvice"/> interface.
/// </summary>
/// <param name="advice">The advice to check.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> is
/// an instance of the <see cref="Spring.Aop.IThrowsAdvice"/> interface;
/// <see langword="false"/> if not or if the supplied
/// <paramref name="advice"/> is <cref lang="null"/>.
/// </returns>
public virtual bool SupportsAdvice(IAdvice advice)
{
return advice is IThrowsAdvice;
}
/// <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);
}
}
}

View File

@@ -1,319 +1,318 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using AopAlliance.Intercept;
using Common.Logging;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>Interceptor to wrap an after throwing advice.</summary>
/// <remarks>
/// <p>
/// Implementations of the <see cref="Spring.Aop.IThrowsAdvice"/> interface
/// <b>must</b> define methods of the form...
/// <code lang="C#">
/// AfterThrowing([MethodInfo method, Object[] args, Object target], Exception subclass);
/// </code>
/// The method name is fixed (i.e. your methods <b>must</b> be named
/// <c>AfterThrowing</c>. The first three arguments (<i>as a whole</i>) are
/// optional, and only useful if futher information about the joinpoint is
/// required. The return type <i>can</i> be anything, but is almost always
/// <see langword="void"/> by convention.
/// </p>
/// <p>
/// Please note that the object encapsulating the throws advice does not
/// need to implement the <see cref="Spring.Aop.IThrowsAdvice"/> interface.
/// Throws advice methods are discovered via reflection... the
/// <see cref="Spring.Aop.IThrowsAdvice"/> interface serves merely to
/// <i>discover</i> objects that are to be considered as throws advice.
/// Other mechanisms for discovering throws advice such as attributes are
/// also equally valid... all that this class cares about is that a throws
/// advice object implement one or more methods with a valid throws advice
/// signature (see above, and the examples below).
/// </p>
/// <p>
/// This is a framework class that should not normally need to be used
/// directly by Spring.NET users.
/// </p>
/// </remarks>
/// <example>
/// <p>
/// Find below some examples of valid <see cref="Spring.Aop.IThrowsAdvice"/>
/// method signatures...
/// </p>
/// <code language="C#">
/// public class GlobalExceptionHandlingAdvice : IThrowsAdvice
/// {
/// public void AfterThrowing(Exception ex) {
/// // handles absolutely any and every Exception...
/// }
/// }
/// </code>
/// <code language="C#">
/// public class RemotingExceptionHandlingAdvice : IThrowsAdvice
/// {
/// public void AfterThrowing(RemotingException ex) {
/// // handles any and every RemotingException (and subclasses of RemotingException)...
/// }
/// }
/// </code>
/// <code language="C#">
/// using System.Data;
///
/// public class DataExceptionHandlingAdvice
/// {
/// public void AfterThrowing(ConstraintException ex) {
/// // specialised handling of ConstraintExceptions
/// }
///
/// public void AfterThrowing(NoNullAllowedException ex) {
/// // specialised handling of NoNullAllowedExceptions
/// }
///
/// public void AfterThrowing(DataException ex) {
/// // handles all other DataExceptions...
/// }
/// }
/// </code>
/// </example>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ThrowsAdviceInterceptor.cs,v 1.8 2007/05/04 13:16:44 bbaia Exp $</version>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
[Serializable]
public sealed class ThrowsAdviceInterceptor : IMethodInterceptor
{
private static readonly ILog log = LogManager.GetLogger(typeof(ThrowsAdviceInterceptor));
private const string SpecialThrowingMethodName = "AfterThrowing";
private readonly object throwsAdvice;
/// <summary>
/// The mapping of exception Types to MethodInfo handlers.
/// </summary>
private readonly IDictionary exceptionHandlers;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/> class.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="advice">
/// The throws advice to check for exception handler methods.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// If no (0) handler methods were discovered on the supplied <paramref name="advice"/>;
/// or if more than one handler method suitable for a particular
/// <see cref="System.Exception"/> type was discovered on the supplied
/// <paramref name="advice"/>.
/// </exception>
public ThrowsAdviceInterceptor(object advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.exceptionHandlers = new Hashtable();
this.throwsAdvice = advice;
MapAllExceptionHandlingMethods(advice);
if (exceptionHandlers.Count == 0)
{
throw new ArgumentException(
"At least one handler method must be found in class ["
+ advice.GetType().FullName + "].");
}
}
private void MapAllExceptionHandlingMethods(object advice)
{
MethodInfo[] methods = advice.GetType().GetMethods();
foreach (MethodInfo method in methods)
{
int numParams = method.GetParameters().Length;
if (method.Name.Equals(SpecialThrowingMethodName)
&& (numParams == 1 || numParams == 4))
{
Type lastParametersType = method.GetParameters()[numParams - 1].ParameterType;
if (typeof (Exception).IsAssignableFrom(lastParametersType))
{
#region Instrumentation
if(log.IsDebugEnabled)
{
log.Debug("Found exception handler method: " + method);
}
#endregion
if(this.exceptionHandlers.Contains(lastParametersType))
{
throw new ArgumentException(
"Throws advice handler method for the [" +
lastParametersType + "] type already exists; don't define " +
"both single and multiple argument methods for the same " +
"Exception type in the same class.");
}
this.exceptionHandlers[lastParametersType] = method;
}
}
}
}
/// <summary>
/// Convenience property that returns the number of exception handler
/// methods managed by this interceptor.
/// </summary>
/// <value>
/// The number of exception handler methods managed by this interceptor.
/// </value>
public int HandlerMethodCount
{
get { return exceptionHandlers.Count; }
}
/// <summary>
/// Executes interceptor if (and only if) the supplied
/// <paramref name="invocation"/> throws an exception that is mapped to
/// an appropriate exception handler.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/> (this assumes no
/// exception was thrown by the call to the supplied <paramref name="invocation"/>.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor.Invoke"/>
public object Invoke(IMethodInvocation invocation)
{
try
{
return invocation.Proceed();
}
catch (TargetInvocationException ex)
{
// bah, this is a tad gross...
Exception realException = ex.InnerException;
LookupAndInvokeAnyHandler(realException, invocation);
throw realException;
}
catch (Exception ex)
{
LookupAndInvokeAnyHandler(ex, invocation);
throw ex;
}
}
private void LookupAndInvokeAnyHandler(Exception ex, IMethodInvocation invocation)
{
MethodInfo handlerMethod = GetExceptionHandler(ex);
if (handlerMethod != null)
{
InvokeHandlerMethod(invocation, ex, handlerMethod);
}
}
/// <summary>
/// Gets the exception handler (if any) that has been mapped to the
/// supplied <paramref name="exception"/>.
/// </summary>
/// <remarks>
/// <p>
/// Will return <cref lang="null"/> if not found.
/// </p>
/// </remarks>
/// <returns>
/// The exception handler for the <see cref="System.Type"/> of the
/// supplied <paramref name="exception"/> given exception.
/// </returns>
/// <param name="exception">exception that was thrown</param>
private MethodInfo GetExceptionHandler(Exception exception)
{
Type exceptionClass = exception.GetType();
#region Instrumentation
if(log.IsDebugEnabled)
{
log.Debug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
}
#endregion
MethodInfo handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
while (handler == null && !exceptionClass.Equals(typeof(Exception)))
{
exceptionClass = exceptionClass.BaseType;
handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
}
return handler;
}
/// <summary>
/// Invokes handler method with appropriate number of parameters
/// </summary>
/// <param name="invocation">
/// The original method invocation that was intercepted.
/// </param>
/// <param name="triggeringException">
/// The exception that triggered this interceptor.
/// </param>
/// <param name="handlerMethod">
/// The exception handler method to invoke.
/// </param>
private void InvokeHandlerMethod(
IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
{
object[] handlerArgs;
if (handlerMethod.GetParameters().Length == 1)
{
handlerArgs = new object[] {triggeringException};
}
else
{
handlerArgs = new object[] {invocation.Method, invocation.Arguments, invocation.This, triggeringException};
}
try
{
handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using AopAlliance.Intercept;
using Common.Logging;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>Interceptor to wrap an after throwing advice.</summary>
/// <remarks>
/// <p>
/// Implementations of the <see cref="Spring.Aop.IThrowsAdvice"/> interface
/// <b>must</b> define methods of the form...
/// <code lang="C#">
/// AfterThrowing([MethodInfo method, Object[] args, Object target], Exception subclass);
/// </code>
/// The method name is fixed (i.e. your methods <b>must</b> be named
/// <c>AfterThrowing</c>. The first three arguments (<i>as a whole</i>) are
/// optional, and only useful if futher information about the joinpoint is
/// required. The return type <i>can</i> be anything, but is almost always
/// <see langword="void"/> by convention.
/// </p>
/// <p>
/// Please note that the object encapsulating the throws advice does not
/// need to implement the <see cref="Spring.Aop.IThrowsAdvice"/> interface.
/// Throws advice methods are discovered via reflection... the
/// <see cref="Spring.Aop.IThrowsAdvice"/> interface serves merely to
/// <i>discover</i> objects that are to be considered as throws advice.
/// Other mechanisms for discovering throws advice such as attributes are
/// also equally valid... all that this class cares about is that a throws
/// advice object implement one or more methods with a valid throws advice
/// signature (see above, and the examples below).
/// </p>
/// <p>
/// This is a framework class that should not normally need to be used
/// directly by Spring.NET users.
/// </p>
/// </remarks>
/// <example>
/// <p>
/// Find below some examples of valid <see cref="Spring.Aop.IThrowsAdvice"/>
/// method signatures...
/// </p>
/// <code language="C#">
/// public class GlobalExceptionHandlingAdvice : IThrowsAdvice
/// {
/// public void AfterThrowing(Exception ex) {
/// // handles absolutely any and every Exception...
/// }
/// }
/// </code>
/// <code language="C#">
/// public class RemotingExceptionHandlingAdvice : IThrowsAdvice
/// {
/// public void AfterThrowing(RemotingException ex) {
/// // handles any and every RemotingException (and subclasses of RemotingException)...
/// }
/// }
/// </code>
/// <code language="C#">
/// using System.Data;
///
/// public class DataExceptionHandlingAdvice
/// {
/// public void AfterThrowing(ConstraintException ex) {
/// // specialised handling of ConstraintExceptions
/// }
///
/// public void AfterThrowing(NoNullAllowedException ex) {
/// // specialised handling of NoNullAllowedExceptions
/// }
///
/// public void AfterThrowing(DataException ex) {
/// // handles all other DataExceptions...
/// }
/// }
/// </code>
/// </example>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
[Serializable]
public sealed class ThrowsAdviceInterceptor : IMethodInterceptor
{
private static readonly ILog log = LogManager.GetLogger(typeof(ThrowsAdviceInterceptor));
private const string SpecialThrowingMethodName = "AfterThrowing";
private readonly object throwsAdvice;
/// <summary>
/// The mapping of exception Types to MethodInfo handlers.
/// </summary>
private readonly IDictionary exceptionHandlers;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/> class.
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="advice">
/// The throws advice to check for exception handler methods.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// If no (0) handler methods were discovered on the supplied <paramref name="advice"/>;
/// or if more than one handler method suitable for a particular
/// <see cref="System.Exception"/> type was discovered on the supplied
/// <paramref name="advice"/>.
/// </exception>
public ThrowsAdviceInterceptor(object advice)
{
AssertUtils.ArgumentNotNull(advice, "advice");
this.exceptionHandlers = new Hashtable();
this.throwsAdvice = advice;
MapAllExceptionHandlingMethods(advice);
if (exceptionHandlers.Count == 0)
{
throw new ArgumentException(
"At least one handler method must be found in class ["
+ advice.GetType().FullName + "].");
}
}
private void MapAllExceptionHandlingMethods(object advice)
{
MethodInfo[] methods = advice.GetType().GetMethods();
foreach (MethodInfo method in methods)
{
int numParams = method.GetParameters().Length;
if (method.Name.Equals(SpecialThrowingMethodName)
&& (numParams == 1 || numParams == 4))
{
Type lastParametersType = method.GetParameters()[numParams - 1].ParameterType;
if (typeof (Exception).IsAssignableFrom(lastParametersType))
{
#region Instrumentation
if(log.IsDebugEnabled)
{
log.Debug("Found exception handler method: " + method);
}
#endregion
if(this.exceptionHandlers.Contains(lastParametersType))
{
throw new ArgumentException(
"Throws advice handler method for the [" +
lastParametersType + "] type already exists; don't define " +
"both single and multiple argument methods for the same " +
"Exception type in the same class.");
}
this.exceptionHandlers[lastParametersType] = method;
}
}
}
}
/// <summary>
/// Convenience property that returns the number of exception handler
/// methods managed by this interceptor.
/// </summary>
/// <value>
/// The number of exception handler methods managed by this interceptor.
/// </value>
public int HandlerMethodCount
{
get { return exceptionHandlers.Count; }
}
/// <summary>
/// Executes interceptor if (and only if) the supplied
/// <paramref name="invocation"/> throws an exception that is mapped to
/// an appropriate exception handler.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/> (this assumes no
/// exception was thrown by the call to the supplied <paramref name="invocation"/>.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor.Invoke"/>
public object Invoke(IMethodInvocation invocation)
{
try
{
return invocation.Proceed();
}
catch (TargetInvocationException ex)
{
// bah, this is a tad gross...
Exception realException = ex.InnerException;
LookupAndInvokeAnyHandler(realException, invocation);
throw realException;
}
catch (Exception ex)
{
LookupAndInvokeAnyHandler(ex, invocation);
throw ex;
}
}
private void LookupAndInvokeAnyHandler(Exception ex, IMethodInvocation invocation)
{
MethodInfo handlerMethod = GetExceptionHandler(ex);
if (handlerMethod != null)
{
InvokeHandlerMethod(invocation, ex, handlerMethod);
}
}
/// <summary>
/// Gets the exception handler (if any) that has been mapped to the
/// supplied <paramref name="exception"/>.
/// </summary>
/// <remarks>
/// <p>
/// Will return <cref lang="null"/> if not found.
/// </p>
/// </remarks>
/// <returns>
/// The exception handler for the <see cref="System.Type"/> of the
/// supplied <paramref name="exception"/> given exception.
/// </returns>
/// <param name="exception">exception that was thrown</param>
private MethodInfo GetExceptionHandler(Exception exception)
{
Type exceptionClass = exception.GetType();
#region Instrumentation
if(log.IsDebugEnabled)
{
log.Debug("Trying to find handler for exception of type [" + exception.GetType().Name + "].");
}
#endregion
MethodInfo handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
while (handler == null && !exceptionClass.Equals(typeof(Exception)))
{
exceptionClass = exceptionClass.BaseType;
handler = (MethodInfo) this.exceptionHandlers[exceptionClass];
}
return handler;
}
/// <summary>
/// Invokes handler method with appropriate number of parameters
/// </summary>
/// <param name="invocation">
/// The original method invocation that was intercepted.
/// </param>
/// <param name="triggeringException">
/// The exception that triggered this interceptor.
/// </param>
/// <param name="handlerMethod">
/// The exception handler method to invoke.
/// </param>
private void InvokeHandlerMethod(
IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
{
object[] handlerArgs;
if (handlerMethod.GetParameters().Length == 1)
{
handlerArgs = new object[] {triggeringException};
}
else
{
handlerArgs = new object[] {invocation.Method, invocation.Arguments, invocation.This, triggeringException};
}
try
{
handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
}
}
}

View File

@@ -1,105 +1,104 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Exception thrown when an attempt is made to use an unsupported
/// <see cref="Spring.Aop.IAdvisor"/> or <see cref="AopAlliance.Aop.IAdvice"/>
/// type.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: UnknownAdviceTypeException.cs,v 1.4 2006/04/09 07:18:35 markpollack Exp $</version>
[Serializable]
public class UnknownAdviceTypeException : ArgumentException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
/// <param name="advice">The advice that caused the exception.</param>
public UnknownAdviceTypeException(object advice)
: base("No adapter for IAdvice of type ["
+ (advice != null ? advice.GetType().FullName : "null") + "].")
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
public UnknownAdviceTypeException()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class with
/// the specified message.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public UnknownAdviceTypeException(string message) : base(message)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class with
/// the specified message and root cause.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception that is being wrapped.
/// </param>
public UnknownAdviceTypeException(string message, Exception rootCause)
: base(message, rootCause)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected UnknownAdviceTypeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Exception thrown when an attempt is made to use an unsupported
/// <see cref="Spring.Aop.IAdvisor"/> or <see cref="AopAlliance.Aop.IAdvice"/>
/// type.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class UnknownAdviceTypeException : ArgumentException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
/// <param name="advice">The advice that caused the exception.</param>
public UnknownAdviceTypeException(object advice)
: base("No adapter for IAdvice of type ["
+ (advice != null ? advice.GetType().FullName : "null") + "].")
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
public UnknownAdviceTypeException()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class with
/// the specified message.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public UnknownAdviceTypeException(string message) : base(message)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class with
/// the specified message and root cause.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception that is being wrapped.
/// </param>
public UnknownAdviceTypeException(string message, Exception rootCause)
: base(message, rootCause)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.Adapter.UnknownAdviceTypeException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected UnknownAdviceTypeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,122 +1,121 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using AopAlliance.Intercept;
using Spring.Aop.Framework.Adapter;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Utility methods for use by
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/> implementations.
/// </summary>
/// <remarks>
/// <p>
/// Not intended to be used directly by applications.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AdvisorChainFactoryUtils.cs,v 1.7 2006/04/09 07:18:35 markpollack Exp $</version>
public sealed class AdvisorChainFactoryUtils
{
/// <summary>
/// Gets the list of
/// <see langword="static"/> interceptors and dynamic interception
/// advice that may apply to the supplied <paramref name="method"/>
/// invocation.
/// </summary>
/// <param name="config">The proxy configuration.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method to evaluate interceptors for.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// A <see cref="System.Collections.IList"/> of
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> (if there's
/// a dynamic method matcher that needs evaluation at runtime).
/// </returns>
public static IList CalculateInterceptors(
IAdvised config, object proxy, MethodInfo method, Type targetType)
{
IList interceptors = new ArrayList(config.Advisors.Length);
foreach (IAdvisor advisor in config.Advisors)
{
if (advisor is IPointcutAdvisor)
{
IPointcutAdvisor pointcutAdvisor = (IPointcutAdvisor) advisor;
if (pointcutAdvisor.Pointcut.TypeFilter.Matches(targetType))
{
IMethodInterceptor interceptor =
(IMethodInterceptor) GlobalAdvisorAdapterRegistry.Instance.GetInterceptor(advisor);
IMethodMatcher mm = pointcutAdvisor.Pointcut.MethodMatcher;
if (mm.Matches(method, targetType))
{
if (mm.IsRuntime)
{
// Creating a new object instance in the GetInterceptor() method
// isn't a problem as we normally cache created chains...
interceptors.Add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
}
else
{
interceptors.Add(interceptor);
}
}
}
}
}
return interceptors;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AdvisorChainFactoryUtils"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible
/// constructors.
/// </p>
/// </remarks>
private AdvisorChainFactoryUtils()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using AopAlliance.Intercept;
using Spring.Aop.Framework.Adapter;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Utility methods for use by
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/> implementations.
/// </summary>
/// <remarks>
/// <p>
/// Not intended to be used directly by applications.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class AdvisorChainFactoryUtils
{
/// <summary>
/// Gets the list of
/// <see langword="static"/> interceptors and dynamic interception
/// advice that may apply to the supplied <paramref name="method"/>
/// invocation.
/// </summary>
/// <param name="config">The proxy configuration.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method to evaluate interceptors for.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// A <see cref="System.Collections.IList"/> of
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> (if there's
/// a dynamic method matcher that needs evaluation at runtime).
/// </returns>
public static IList CalculateInterceptors(
IAdvised config, object proxy, MethodInfo method, Type targetType)
{
IList interceptors = new ArrayList(config.Advisors.Length);
foreach (IAdvisor advisor in config.Advisors)
{
if (advisor is IPointcutAdvisor)
{
IPointcutAdvisor pointcutAdvisor = (IPointcutAdvisor) advisor;
if (pointcutAdvisor.Pointcut.TypeFilter.Matches(targetType))
{
IMethodInterceptor interceptor =
(IMethodInterceptor) GlobalAdvisorAdapterRegistry.Instance.GetInterceptor(advisor);
IMethodMatcher mm = pointcutAdvisor.Pointcut.MethodMatcher;
if (mm.Matches(method, targetType))
{
if (mm.IsRuntime)
{
// Creating a new object instance in the GetInterceptor() method
// isn't a problem as we normally cache created chains...
interceptors.Add(new InterceptorAndDynamicMethodMatcher(interceptor, mm));
}
else
{
interceptors.Add(interceptor);
}
}
}
}
}
return interceptors;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AdvisorChainFactoryUtils"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible
/// constructors.
/// </p>
/// </remarks>
private AdvisorChainFactoryUtils()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,93 +1,92 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Thrown in response to the misconfiguration of an AOP proxy.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AopConfigException.cs,v 1.4 2006/04/09 07:18:35 markpollack Exp $</version>
[Serializable]
public class AopConfigException : ApplicationException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class.
/// </summary>
public AopConfigException ()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class with
/// the specified message.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public AopConfigException (string message) : base(message)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class with
/// the specified message and root cause.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception that is being wrapped.
/// </param>
public AopConfigException (string message, Exception rootCause)
: base(message, rootCause)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected AopConfigException (
SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Thrown in response to the misconfiguration of an AOP proxy.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class AopConfigException : ApplicationException
{
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class.
/// </summary>
public AopConfigException ()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class with
/// the specified message.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
public AopConfigException (string message) : base(message)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class with
/// the specified message and root cause.
/// </summary>
/// <param name="message">
/// A message about the exception.
/// </param>
/// <param name="rootCause">
/// The root exception that is being wrapped.
/// </param>
public AopConfigException (string message, Exception rootCause)
: base(message, rootCause)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopConfigException"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
protected AopConfigException (
SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
}
}

View File

@@ -1,172 +1,171 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System.Collections;
using Spring.Threading;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// This class contains various <see langword="static"/> methods used to
/// obtain information about the current AOP invocation.
/// </summary>
/// <remarks>
/// <p>
/// The <see langword="static"/>
/// <see cref="Spring.Aop.Framework.AopContext.CurrentProxy"/> property is
/// usable if the AOP framework is configured to expose the current proxy
/// (not the default)... it returns the AOP proxy in use. Target objects or
/// advice can use this to make advised calls. They can also use it to find
/// advice configuration.
/// </p>
/// <note>
/// The AOP framework does not expose proxies by default, as there is a
/// performance cost in doing so.
/// </note>
/// <p>
/// The functionality in this class might be used by a target object that
/// needed access to resources on the invocation. However, this approach
/// should not be used when there is a reasonable alternative, as it makes
/// application code dependent on usage under AOP and the Spring.NET AOP
/// framework.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AopContext.cs,v 1.7 2006/09/15 21:25:16 markpollack Exp $</version>
public sealed class AopContext
{
private const string CURRENTPROXY_SLOTNAME = "AopContext.CurrentProxySlotName";
/// <summary>
/// The AOP proxy associated with this thread.
/// </summary>
/// <remarks>
/// <p>
/// Will be <cref lang="null"/> unless the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// on the controlling proxy has been set to <see langword="true"/>.
/// </p>
/// <p>
/// The default value for the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// is <see langword="false"/>, for performance reasons.
/// </p>
/// </remarks>
private static Stack ProxyStack
{
get
{
Stack proxyStack = LogicalThreadContext.GetData(CURRENTPROXY_SLOTNAME) as Stack;
if (proxyStack == null)
{
proxyStack = new Stack();
LogicalThreadContext.SetData(CURRENTPROXY_SLOTNAME, proxyStack);
}
return proxyStack;
}
}
/// <summary>
/// Gets the current AOP proxy.
/// </summary>
/// <exception cref="AopConfigException">
/// If the proxy stack is empty.
/// </exception>
public static object CurrentProxy
{
get
{
if (ProxyStack.Count == 0)
{
throw new AopConfigException(
"Cannot find proxy: Set the 'ExposeProxy' property " +
"to 'true' on IAdvised to make it available.");
}
return ProxyStack.Peek();
}
}
/// <summary>
/// Sets the current proxy by pushing it to the proxy stack.
/// </summary>
/// <remarks>
/// <p>
/// This method is for internal use only, and should never be called by
/// client code.
/// </p>
/// </remarks>
/// <param name="proxy">
/// The proxy to put on top of the proxy stack.
/// </param>
public static void PushProxy(object proxy)
{
ProxyStack.Push(proxy);
}
/// <summary>
/// Removes the current proxy from the proxy stack, making the previous
/// proxy (if any) the current proxy.
/// </summary>
/// <remarks>
/// <p>
/// This method is for internal use only, and should never be called by
/// client code.
/// </p>
/// </remarks>
/// <exception cref="AopConfigException">
/// If the proxy stack is empty.
/// </exception>
public static void PopProxy()
{
if (ProxyStack.Count == 0)
{
throw new AopConfigException(
"Proxy stack empty. Always call 'PushProxy' before 'PopProxy'.");
}
ProxyStack.Pop();
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopContext"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such exposes no public constructors.
/// </p>
/// </remarks>
private AopContext()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System.Collections;
using Spring.Threading;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// This class contains various <see langword="static"/> methods used to
/// obtain information about the current AOP invocation.
/// </summary>
/// <remarks>
/// <p>
/// The <see langword="static"/>
/// <see cref="Spring.Aop.Framework.AopContext.CurrentProxy"/> property is
/// usable if the AOP framework is configured to expose the current proxy
/// (not the default)... it returns the AOP proxy in use. Target objects or
/// advice can use this to make advised calls. They can also use it to find
/// advice configuration.
/// </p>
/// <note>
/// The AOP framework does not expose proxies by default, as there is a
/// performance cost in doing so.
/// </note>
/// <p>
/// The functionality in this class might be used by a target object that
/// needed access to resources on the invocation. However, this approach
/// should not be used when there is a reasonable alternative, as it makes
/// application code dependent on usage under AOP and the Spring.NET AOP
/// framework.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class AopContext
{
private const string CURRENTPROXY_SLOTNAME = "AopContext.CurrentProxySlotName";
/// <summary>
/// The AOP proxy associated with this thread.
/// </summary>
/// <remarks>
/// <p>
/// Will be <cref lang="null"/> unless the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// on the controlling proxy has been set to <see langword="true"/>.
/// </p>
/// <p>
/// The default value for the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// is <see langword="false"/>, for performance reasons.
/// </p>
/// </remarks>
private static Stack ProxyStack
{
get
{
Stack proxyStack = LogicalThreadContext.GetData(CURRENTPROXY_SLOTNAME) as Stack;
if (proxyStack == null)
{
proxyStack = new Stack();
LogicalThreadContext.SetData(CURRENTPROXY_SLOTNAME, proxyStack);
}
return proxyStack;
}
}
/// <summary>
/// Gets the current AOP proxy.
/// </summary>
/// <exception cref="AopConfigException">
/// If the proxy stack is empty.
/// </exception>
public static object CurrentProxy
{
get
{
if (ProxyStack.Count == 0)
{
throw new AopConfigException(
"Cannot find proxy: Set the 'ExposeProxy' property " +
"to 'true' on IAdvised to make it available.");
}
return ProxyStack.Peek();
}
}
/// <summary>
/// Sets the current proxy by pushing it to the proxy stack.
/// </summary>
/// <remarks>
/// <p>
/// This method is for internal use only, and should never be called by
/// client code.
/// </p>
/// </remarks>
/// <param name="proxy">
/// The proxy to put on top of the proxy stack.
/// </param>
public static void PushProxy(object proxy)
{
ProxyStack.Push(proxy);
}
/// <summary>
/// Removes the current proxy from the proxy stack, making the previous
/// proxy (if any) the current proxy.
/// </summary>
/// <remarks>
/// <p>
/// This method is for internal use only, and should never be called by
/// client code.
/// </p>
/// </remarks>
/// <exception cref="AopConfigException">
/// If the proxy stack is empty.
/// </exception>
public static void PopProxy()
{
if (ProxyStack.Count == 0)
{
throw new AopConfigException(
"Proxy stack empty. Always call 'PushProxy' before 'PopProxy'.");
}
ProxyStack.Pop();
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.AopContext"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such exposes no public constructors.
/// </p>
/// </remarks>
private AopContext()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,272 +1,271 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Collections;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Utility methods used by the AOP framework.
/// </summary>
/// <remarks>
/// <p>
/// Not intended to be used directly by applications.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: AopUtils.cs,v 1.4 2007/10/10 18:07:38 markpollack Exp $</version>
public sealed class AopUtils
{
// This is a leaky abstraction as we have hardcoded known IAopProxyFactory implementations.
private const string COMPOSITION_PROXY_TYPE_NAME = "CompositionAopProxy";
private const string DECORATOR_PROXY_TYPE_NAME = "DecoratorAopProxy";
/// <summary>
/// Is the supplied <paramref name="instance"/> an AOP proxy?
/// </summary>
/// <remarks>
/// Return whether the given object is either
/// a composition-based proxy or a decorator-based proxy.
/// </remarks>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an AOP proxy.
/// </returns>
public static bool IsAopProxy(object instance)
{
return IsCompositionAopProxy(instance) || IsDecoratorAopProxy(instance);
}
/// <summary>
/// Is the supplied <paramref name="instance"/> a composition-based AOP proxy?
/// </summary>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an composition-based AOP proxy.
/// </returns>
public static bool IsCompositionAopProxy(Object instance)
{
return ((instance != null) && instance.GetType().FullName.StartsWith(COMPOSITION_PROXY_TYPE_NAME));
}
/// <summary>
/// Is the supplied <paramref name="instance"/> a decorator-based AOP proxy?
/// </summary>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an decorator-based AOP proxy.
/// </returns>
public static bool IsDecoratorAopProxy(Object instance)
{
return ((instance != null) && instance.GetType().FullName.StartsWith(DECORATOR_PROXY_TYPE_NAME));
}
/// <summary>
/// Gets all of the interfaces that the <see cref="System.Type"/> of the
/// supplied <paramref name="instance"/> implements.
/// </summary>
/// <remarks>
/// <p>
/// This includes interfaces implemented by any superclasses.
/// </p>
/// </remarks>
/// <param name="instance">
/// The object to analyse for interfaces.
/// </param>
/// <returns>
/// All of the interfaces that the <see cref="System.Type"/> of the
/// supplied <paramref name="instance"/> implements; or an empty
/// array if the supplied <paramref name="instance"/> is
/// <see langword="null"/>.
/// </returns>
public static Type[] GetAllInterfaces(object instance)
{
if (instance != null)
{
ISet interfaces = new HybridSet();
Type type = instance.GetType();
do
{
Type[] ifcs = type.GetInterfaces();
foreach (Type ifc in ifcs)
{
interfaces.Add(ifc);
}
type = type.BaseType;
} while (type != null);
if (interfaces.Count > 0)
{
Type[] types = new Type[interfaces.Count];
interfaces.CopyTo(types, 0);
return types;
}
}
return Type.EmptyTypes;
}
/// <summary>
/// Can the supplied <paramref name="pointcut"/> 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 a
/// pointcut for a class.
/// </p>
/// <p>
/// Invoking this method with a <paramref name="targetType"/> that is
/// an interface type will always yield a <see langword="false"/>
/// return value.
/// </p>
/// </remarks>
/// <param name="pointcut">The pointcut being tested.</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 pointcut can apply on any method.
/// </returns>
public static bool CanApply(
IPointcut pointcut, Type targetType, Type[] proxyInterfaces)
{
if (!pointcut.TypeFilter.Matches(targetType))
{
return false;
}
// It may apply to the class
// Check whether it can apply on any method
// Checks public methods, including inherited methods
MethodInfo[] methods = targetType.GetMethods();
for (int i = 0; i < methods.Length; ++i)
{
MethodInfo m = methods[i];
// If we're looking only at interfaces and this method
// isn't on any of them, skip it
if (proxyInterfaces != null
&& !ReflectionUtils.MethodIsOnOneOfTheseInterfaces(m, proxyInterfaces))
{
continue;
}
if (pointcut.MethodMatcher.Matches(m, targetType))
{
return true;
}
}
return false;
}
/// <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)
{
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);
}
// no pointcut specified so assume it applies...
return true;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="AopUtils"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private AopUtils()
{
}
// CLOVER:ON
#endregion
/// <summary>
/// Gets the type of the target.
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns></returns>
public static Type GetTargetType(object candidate)
{
AssertUtils.ArgumentNotNull(candidate,"candidate", "Candidate object must not be null");
if (candidate is ITargetSource)
{
return ((ITargetSource) candidate).TargetType;
}
if (candidate is IAdvised)
{
return ((IAdvised) candidate).TargetSource.TargetType;
}
if (IsDecoratorAopProxy(candidate))
{
return candidate.GetType().BaseType;
}
return candidate.GetType();
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Collections;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Utility methods used by the AOP framework.
/// </summary>
/// <remarks>
/// <p>
/// Not intended to be used directly by applications.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class AopUtils
{
// This is a leaky abstraction as we have hardcoded known IAopProxyFactory implementations.
private const string COMPOSITION_PROXY_TYPE_NAME = "CompositionAopProxy";
private const string DECORATOR_PROXY_TYPE_NAME = "DecoratorAopProxy";
/// <summary>
/// Is the supplied <paramref name="instance"/> an AOP proxy?
/// </summary>
/// <remarks>
/// Return whether the given object is either
/// a composition-based proxy or a decorator-based proxy.
/// </remarks>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an AOP proxy.
/// </returns>
public static bool IsAopProxy(object instance)
{
return IsCompositionAopProxy(instance) || IsDecoratorAopProxy(instance);
}
/// <summary>
/// Is the supplied <paramref name="instance"/> a composition-based AOP proxy?
/// </summary>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an composition-based AOP proxy.
/// </returns>
public static bool IsCompositionAopProxy(Object instance)
{
return ((instance != null) && instance.GetType().FullName.StartsWith(COMPOSITION_PROXY_TYPE_NAME));
}
/// <summary>
/// Is the supplied <paramref name="instance"/> a decorator-based AOP proxy?
/// </summary>
/// <param name="instance">The instance to be checked.</param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="instance"/> is
/// an decorator-based AOP proxy.
/// </returns>
public static bool IsDecoratorAopProxy(Object instance)
{
return ((instance != null) && instance.GetType().FullName.StartsWith(DECORATOR_PROXY_TYPE_NAME));
}
/// <summary>
/// Gets all of the interfaces that the <see cref="System.Type"/> of the
/// supplied <paramref name="instance"/> implements.
/// </summary>
/// <remarks>
/// <p>
/// This includes interfaces implemented by any superclasses.
/// </p>
/// </remarks>
/// <param name="instance">
/// The object to analyse for interfaces.
/// </param>
/// <returns>
/// All of the interfaces that the <see cref="System.Type"/> of the
/// supplied <paramref name="instance"/> implements; or an empty
/// array if the supplied <paramref name="instance"/> is
/// <see langword="null"/>.
/// </returns>
public static Type[] GetAllInterfaces(object instance)
{
if (instance != null)
{
ISet interfaces = new HybridSet();
Type type = instance.GetType();
do
{
Type[] ifcs = type.GetInterfaces();
foreach (Type ifc in ifcs)
{
interfaces.Add(ifc);
}
type = type.BaseType;
} while (type != null);
if (interfaces.Count > 0)
{
Type[] types = new Type[interfaces.Count];
interfaces.CopyTo(types, 0);
return types;
}
}
return Type.EmptyTypes;
}
/// <summary>
/// Can the supplied <paramref name="pointcut"/> 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 a
/// pointcut for a class.
/// </p>
/// <p>
/// Invoking this method with a <paramref name="targetType"/> that is
/// an interface type will always yield a <see langword="false"/>
/// return value.
/// </p>
/// </remarks>
/// <param name="pointcut">The pointcut being tested.</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 pointcut can apply on any method.
/// </returns>
public static bool CanApply(
IPointcut pointcut, Type targetType, Type[] proxyInterfaces)
{
if (!pointcut.TypeFilter.Matches(targetType))
{
return false;
}
// It may apply to the class
// Check whether it can apply on any method
// Checks public methods, including inherited methods
MethodInfo[] methods = targetType.GetMethods();
for (int i = 0; i < methods.Length; ++i)
{
MethodInfo m = methods[i];
// If we're looking only at interfaces and this method
// isn't on any of them, skip it
if (proxyInterfaces != null
&& !ReflectionUtils.MethodIsOnOneOfTheseInterfaces(m, proxyInterfaces))
{
continue;
}
if (pointcut.MethodMatcher.Matches(m, targetType))
{
return true;
}
}
return false;
}
/// <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)
{
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);
}
// no pointcut specified so assume it applies...
return true;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="AopUtils"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private AopUtils()
{
}
// CLOVER:ON
#endregion
/// <summary>
/// Gets the type of the target.
/// </summary>
/// <param name="candidate">The candidate.</param>
/// <returns></returns>
public static Type GetTargetType(object candidate)
{
AssertUtils.ArgumentNotNull(candidate,"candidate", "Candidate object must not be null");
if (candidate is ITargetSource)
{
return ((ITargetSource) candidate).TargetType;
}
if (candidate is IAdvised)
{
return ((IAdvised) candidate).TargetSource.TargetType;
}
if (IsDecoratorAopProxy(candidate))
{
return candidate.GetType().BaseType;
}
return candidate.GetType();
}
}
}

View File

@@ -1,166 +1,165 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Core;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Abstract IOBjectPostProcessor implementation that creates AOP proxies.
/// This class is completely generic; it contains no special code to handle
/// any particular aspects, such as pooling aspects.
/// </summary>
/// <remarks>
/// <p>Subclasses must implement the abstract findCandidateAdvisors() method
/// to return a list of Advisors applying to any object. Subclasses can also
/// override the inherited shouldSkip() method to exclude certain objects
/// from autoproxying, but they must be careful to invoke the shouldSkip()
/// method of this class, which tries to avoid circular reference problems
/// and infinite loops.</p>
/// <p>Advisors or advices requiring ordering should implement the Ordered interface.
/// This class sorts advisors by Ordered order value. Advisors that don't implement
/// the Ordered interface will be considered to be unordered, and will appear
/// at the end of the advisor chain in undefined order.</p>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.AutoProxy.AbstractAdvisorAutoProxyCreator.FindCandidateAdvisors"/>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
/// <version>$Id: AbstractAdvisorAutoProxyCreator.cs,v 1.5 2007/08/22 08:49:08 markpollack Exp $</version>
public abstract class AbstractAdvisorAutoProxyCreator : AbstractAutoProxyCreator
{
/// <summary>
/// We override this method to ensure that all candidate advisors are materialized
/// under a stack trace including this object. Otherwise, the dependencies won't
/// be apparent to the circular-reference prevention strategy in AbstractObjectFactory.
/// </summary>
public override IObjectFactory ObjectFactory
{
//TODO investigate override...
set
{
base.ObjectFactory = value;
if (!(value is IConfigurableListableObjectFactory))
{
throw new InvalidOperationException(
"Can not use AdvisorAutoProxyCreator without a ConfigurableListableObjectFactory");
}
}
get { return base.ObjectFactory; }
}
/// <summary>
/// Return whether the given object is to be proxied, what additional
/// advices (e.g. AOP Alliance interceptors) and advisors to apply.
/// </summary>
/// <param name="objType">the new object instance</param>
/// <param name="name">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>
/// <remarks>
/// <p>The previous name 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>
protected override object[] GetAdvicesAndAdvisorsForObject(Type objType, string name, ITargetSource customTargetSource)
{
IList advisors = FindEligibleAdvisors(objType);
if (advisors.Count == 0)
{
return DO_NOT_PROXY;
}
advisors = SortAdvisors(advisors);
if (advisors is ArrayList)
return ((ArrayList) advisors).ToArray();
else
{
return advisors as object[];
}
}
/// <summary>
/// Find all eligible advices and for autoproxying this class.
/// </summary>
/// <param name="type"></param>
/// <returns>the empty list, not null, if there are no pointcuts or interceptors</returns>
protected IList FindEligibleAdvisors(Type type)
{
IList candidateAdvisors = FindCandidateAdvisors();
IList eligibleAdvisors = new ArrayList();
for (int i = 0; i < candidateAdvisors.Count; i++)
{
IAdvisor candidate = (IAdvisor) candidateAdvisors[i];
if (AopUtils.CanApply(candidate, type, null))
{
eligibleAdvisors.Add(candidate);
if (logger.IsInfoEnabled)
{
logger.Info(string.Format("Candidate advisor [{0}] accepted for type [{1}]", candidate, type.ToString()));
}
}
else
{
if (logger.IsInfoEnabled)
{
logger.Info(string.Format("Candidate advisor [{0}] rejected for type [{1}]", candidate, type.ToString()));
}
}
}
return eligibleAdvisors;
}
/// <summary>
/// Sorts the advisors.
/// </summary>
/// <param name="advisors">The advisors.</param>
/// <returns></returns>
protected IList SortAdvisors(IList advisors)
{
if (advisors is ArrayList)
((ArrayList) advisors).Sort(new OrderComparator());
else if (advisors is Array)
Array.Sort((Array) advisors, new OrderComparator());
return advisors;
}
/// <summary>
/// Find all candidate advisors to use in auto-proxying.
/// </summary>
/// <returns>list of Advisors</returns>
protected abstract IList FindCandidateAdvisors();
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Core;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Abstract IOBjectPostProcessor implementation that creates AOP proxies.
/// This class is completely generic; it contains no special code to handle
/// any particular aspects, such as pooling aspects.
/// </summary>
/// <remarks>
/// <p>Subclasses must implement the abstract findCandidateAdvisors() method
/// to return a list of Advisors applying to any object. Subclasses can also
/// override the inherited shouldSkip() method to exclude certain objects
/// from autoproxying, but they must be careful to invoke the shouldSkip()
/// method of this class, which tries to avoid circular reference problems
/// and infinite loops.</p>
/// <p>Advisors or advices requiring ordering should implement the Ordered interface.
/// This class sorts advisors by Ordered order value. Advisors that don't implement
/// the Ordered interface will be considered to be unordered, and will appear
/// at the end of the advisor chain in undefined order.</p>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.AutoProxy.AbstractAdvisorAutoProxyCreator.FindCandidateAdvisors"/>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
public abstract class AbstractAdvisorAutoProxyCreator : AbstractAutoProxyCreator
{
/// <summary>
/// We override this method to ensure that all candidate advisors are materialized
/// under a stack trace including this object. Otherwise, the dependencies won't
/// be apparent to the circular-reference prevention strategy in AbstractObjectFactory.
/// </summary>
public override IObjectFactory ObjectFactory
{
//TODO investigate override...
set
{
base.ObjectFactory = value;
if (!(value is IConfigurableListableObjectFactory))
{
throw new InvalidOperationException(
"Can not use AdvisorAutoProxyCreator without a ConfigurableListableObjectFactory");
}
}
get { return base.ObjectFactory; }
}
/// <summary>
/// Return whether the given object is to be proxied, what additional
/// advices (e.g. AOP Alliance interceptors) and advisors to apply.
/// </summary>
/// <param name="objType">the new object instance</param>
/// <param name="name">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>
/// <remarks>
/// <p>The previous name 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>
protected override object[] GetAdvicesAndAdvisorsForObject(Type objType, string name, ITargetSource customTargetSource)
{
IList advisors = FindEligibleAdvisors(objType);
if (advisors.Count == 0)
{
return DO_NOT_PROXY;
}
advisors = SortAdvisors(advisors);
if (advisors is ArrayList)
return ((ArrayList) advisors).ToArray();
else
{
return advisors as object[];
}
}
/// <summary>
/// Find all eligible advices and for autoproxying this class.
/// </summary>
/// <param name="type"></param>
/// <returns>the empty list, not null, if there are no pointcuts or interceptors</returns>
protected IList FindEligibleAdvisors(Type type)
{
IList candidateAdvisors = FindCandidateAdvisors();
IList eligibleAdvisors = new ArrayList();
for (int i = 0; i < candidateAdvisors.Count; i++)
{
IAdvisor candidate = (IAdvisor) candidateAdvisors[i];
if (AopUtils.CanApply(candidate, type, null))
{
eligibleAdvisors.Add(candidate);
if (logger.IsInfoEnabled)
{
logger.Info(string.Format("Candidate advisor [{0}] accepted for type [{1}]", candidate, type.ToString()));
}
}
else
{
if (logger.IsInfoEnabled)
{
logger.Info(string.Format("Candidate advisor [{0}] rejected for type [{1}]", candidate, type.ToString()));
}
}
}
return eligibleAdvisors;
}
/// <summary>
/// Sorts the advisors.
/// </summary>
/// <param name="advisors">The advisors.</param>
/// <returns></returns>
protected IList SortAdvisors(IList advisors)
{
if (advisors is ArrayList)
((ArrayList) advisors).Sort(new OrderComparator());
else if (advisors is Array)
Array.Sort((Array) advisors, new OrderComparator());
return advisors;
}
/// <summary>
/// Find all candidate advisors to use in auto-proxying.
/// </summary>
/// <returns>list of Advisors</returns>
protected abstract IList FindCandidateAdvisors();
}
}

View File

@@ -1,198 +1,197 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// ObjectPostProcessor implementation that creates AOP proxies based on all candidate
/// Advisors in the current IObjectFactory. This class is completely generic; it contains
/// no special code to handle any particular aspects, such as pooling aspects.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
/// <version>$Id: DefaultAdvisorAutoProxyCreator.cs,v 1.9 2007/10/08 22:04:51 markpollack Exp $</version>
public class DefaultAdvisorAutoProxyCreator : AbstractAdvisorAutoProxyCreator, IObjectNameAware, IInitializingObject
{
/// <summary>
/// Separator between prefix and remainder of object name
/// </summary>
public static readonly string SEPARATOR = ".";
private bool usePrefix;
private string advisorObjectNamePrefix;
private IList advisors;
#region Properties
/// <summary>
/// Gets or sets a value indicating whether to exclude
/// advisors with a certain prefix.
/// </summary>
/// <value><c>true</c> if [use prefix]; otherwise, <c>false</c>.</value>
public bool UsePrefix
{
get { return usePrefix; }
set { usePrefix = value; }
}
/// <summary>
/// Set the prefix for object names that will cause them to be included for
/// auto-proxying by this object. This prefix should be set to avoid circular
/// references. Default value is the object name of this object + a dot.
/// </summary>
/// <value>The advisor object name prefix.</value>
public string AdvisorObjectNamePrefix
{
get { return advisorObjectNamePrefix; }
set { advisorObjectNamePrefix = value; }
}
#endregion
/// <summary>
/// Find all candidate advices to use in auto proxying.
/// </summary>
/// <returns>list of Advice</returns>
protected override IList FindCandidateAdvisors()
{
if (advisors == null)
{
throw new InvalidOperationException("Must not be called before AfterPropertiesSet()");
}
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("returning available advisors"));
}
return advisors;
}
private IList InstantiateCandidateAdvisors()
{
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("instantiating available advisors"));
}
//This is ensured in AbstractAdvisorAutoProxyCreator. Will be more type safe once sync with Spring Java 2.x
IConfigurableListableObjectFactory owningFactory = ObjectFactory as IConfigurableListableObjectFactory;
if (owningFactory == null)
{
throw new InvalidOperationException("Cannot use DefaultAdvisorAutoProxyCreator without a IListableObjectFactory");
}
ArrayList candidateAdvisors = new ArrayList();
string[] advisorNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(
owningFactory, typeof(IAdvisor), true, false);
for (int i = 0; i < advisorNames.Length; i++)
{
string name = advisorNames[i];
if ( (!usePrefix || name.StartsWith(advisorObjectNamePrefix)) && !owningFactory.IsCurrentlyInCreation(name))
{
try
{
IAdvisor advisor = (IAdvisor) owningFactory.GetObject(name);
candidateAdvisors.Add(advisor);
} catch (ObjectCreationException ex)
{
Exception rootEx = ex.GetBaseException();
if (rootEx is ObjectCurrentlyInCreationException)
{
ObjectCurrentlyInCreationException oce = (ObjectCurrentlyInCreationException) rootEx;
if (owningFactory.IsCurrentlyInCreation(oce.ObjectName))
{
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("Ignoring currently created advisor '{0}': exception message = {1}",
name, ex.Message));
}
continue;
}
}
throw;
}
}
}
string[] aspectNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(
owningFactory, typeof(IAdvisors), true, false);
for (int i = 0; i < aspectNames.Length; i++)
{
string name = aspectNames[i];
if (!usePrefix || name.StartsWith(advisorObjectNamePrefix))
{
IAdvisors advisors = (IAdvisors)owningFactory.GetObject(name);
candidateAdvisors.AddRange(advisors.Advisors);
}
}
return candidateAdvisors;
}
/// <summary>
/// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// after it has injected all of an object's dependencies.
/// </summary>
public void AfterPropertiesSet()
{
advisors = InstantiateCandidateAdvisors();
}
#region IObjectNameAware Members
/// <summary>
/// Set the name of the object in the object factory that created this object.
/// </summary>
/// <value>The name of the object in the factory.</value>
/// <remarks>
/// <p>
/// Invoked after population of normal object properties but before an init
/// callback like <see cref="T:Spring.Objects.Factory.IInitializingObject"/>'s
/// <see cref="M:Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
/// method or a custom init-method.
/// </p>
/// </remarks>
public string ObjectName
{
set
{
// If no infrastructure object name prefix has been set, override it.
if (advisorObjectNamePrefix == null)
{
advisorObjectNamePrefix = value + SEPARATOR;
}
}
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Config;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// ObjectPostProcessor implementation that creates AOP proxies based on all candidate
/// Advisors in the current IObjectFactory. This class is completely generic; it contains
/// no special code to handle any particular aspects, such as pooling aspects.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
public class DefaultAdvisorAutoProxyCreator : AbstractAdvisorAutoProxyCreator, IObjectNameAware, IInitializingObject
{
/// <summary>
/// Separator between prefix and remainder of object name
/// </summary>
public static readonly string SEPARATOR = ".";
private bool usePrefix;
private string advisorObjectNamePrefix;
private IList advisors;
#region Properties
/// <summary>
/// Gets or sets a value indicating whether to exclude
/// advisors with a certain prefix.
/// </summary>
/// <value><c>true</c> if [use prefix]; otherwise, <c>false</c>.</value>
public bool UsePrefix
{
get { return usePrefix; }
set { usePrefix = value; }
}
/// <summary>
/// Set the prefix for object names that will cause them to be included for
/// auto-proxying by this object. This prefix should be set to avoid circular
/// references. Default value is the object name of this object + a dot.
/// </summary>
/// <value>The advisor object name prefix.</value>
public string AdvisorObjectNamePrefix
{
get { return advisorObjectNamePrefix; }
set { advisorObjectNamePrefix = value; }
}
#endregion
/// <summary>
/// Find all candidate advices to use in auto proxying.
/// </summary>
/// <returns>list of Advice</returns>
protected override IList FindCandidateAdvisors()
{
if (advisors == null)
{
throw new InvalidOperationException("Must not be called before AfterPropertiesSet()");
}
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("returning available advisors"));
}
return advisors;
}
private IList InstantiateCandidateAdvisors()
{
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("instantiating available advisors"));
}
//This is ensured in AbstractAdvisorAutoProxyCreator. Will be more type safe once sync with Spring Java 2.x
IConfigurableListableObjectFactory owningFactory = ObjectFactory as IConfigurableListableObjectFactory;
if (owningFactory == null)
{
throw new InvalidOperationException("Cannot use DefaultAdvisorAutoProxyCreator without a IListableObjectFactory");
}
ArrayList candidateAdvisors = new ArrayList();
string[] advisorNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(
owningFactory, typeof(IAdvisor), true, false);
for (int i = 0; i < advisorNames.Length; i++)
{
string name = advisorNames[i];
if ( (!usePrefix || name.StartsWith(advisorObjectNamePrefix)) && !owningFactory.IsCurrentlyInCreation(name))
{
try
{
IAdvisor advisor = (IAdvisor) owningFactory.GetObject(name);
candidateAdvisors.Add(advisor);
} catch (ObjectCreationException ex)
{
Exception rootEx = ex.GetBaseException();
if (rootEx is ObjectCurrentlyInCreationException)
{
ObjectCurrentlyInCreationException oce = (ObjectCurrentlyInCreationException) rootEx;
if (owningFactory.IsCurrentlyInCreation(oce.ObjectName))
{
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("Ignoring currently created advisor '{0}': exception message = {1}",
name, ex.Message));
}
continue;
}
}
throw;
}
}
}
string[] aspectNames = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(
owningFactory, typeof(IAdvisors), true, false);
for (int i = 0; i < aspectNames.Length; i++)
{
string name = aspectNames[i];
if (!usePrefix || name.StartsWith(advisorObjectNamePrefix))
{
IAdvisors advisors = (IAdvisors)owningFactory.GetObject(name);
candidateAdvisors.AddRange(advisors.Advisors);
}
}
return candidateAdvisors;
}
/// <summary>
/// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// after it has injected all of an object's dependencies.
/// </summary>
public void AfterPropertiesSet()
{
advisors = InstantiateCandidateAdvisors();
}
#region IObjectNameAware Members
/// <summary>
/// Set the name of the object in the object factory that created this object.
/// </summary>
/// <value>The name of the object in the factory.</value>
/// <remarks>
/// <p>
/// Invoked after population of normal object properties but before an init
/// callback like <see cref="T:Spring.Objects.Factory.IInitializingObject"/>'s
/// <see cref="M:Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
/// method or a custom init-method.
/// </p>
/// </remarks>
public string ObjectName
{
set
{
// If no infrastructure object name prefix has been set, override it.
if (advisorObjectNamePrefix == null)
{
advisorObjectNamePrefix = value + SEPARATOR;
}
}
}
#endregion
}
}

View File

@@ -1,53 +1,52 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Objects.Factory;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Implementations can create special target sources, such as pooling target
/// sources, for particular objects. For example, they may base their choice
/// on attributes, such as a pooling attribute, on the target type.
/// </summary>
/// <remarks><p>AbstractAutoProxyCreator can support a number of TargetSourceCreators,
/// which will be applied in order.</p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
/// <version>$Id: ITargetSourceCreator.cs,v 1.3 2007/08/22 08:49:08 markpollack Exp $</version>
public interface ITargetSourceCreator
{
/// <summary>
/// Create a special TargetSource for the given object, if any.
/// </summary>
/// <param name="objectType">The type of the object to create a TargetSource for</param>
/// <param name="objectName">the name of the object</param>
/// <param name="factory">the containing factory</param>
/// <returns>a special TargetSource or null if this TargetSourceCreator isn't
/// interested in the particular object</returns>
ITargetSource GetTargetSource(Type objectType, string objectName, IObjectFactory factory);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Objects.Factory;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Implementations can create special target sources, such as pooling target
/// sources, for particular objects. For example, they may base their choice
/// on attributes, such as a pooling attribute, on the target type.
/// </summary>
/// <remarks><p>AbstractAutoProxyCreator can support a number of TargetSourceCreators,
/// which will be applied in order.</p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Adhari C Mahendra (.NET)</author>
public interface ITargetSourceCreator
{
/// <summary>
/// Create a special TargetSource for the given object, if any.
/// </summary>
/// <param name="objectType">The type of the object to create a TargetSource for</param>
/// <param name="objectName">the name of the object</param>
/// <param name="factory">the containing factory</param>
/// <returns>a special TargetSource or null if this TargetSourceCreator isn't
/// interested in the particular object</returns>
ITargetSource GetTargetSource(Type objectType, string objectName, IObjectFactory factory);
}
}

View File

@@ -1,112 +1,111 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Objects.Factory;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Object Auto Proxy Creator
/// </summary>
/// <remarks>
/// <para>
/// Auto proxy creator that identifies objects to proxy via a list of names.
/// Checks for direct, "xxx*", "*xxx" and "*xxx*" matches.
/// </para>
/// <para>In case of a IFactoryObject, only the objects created by the
/// FactoryBean will get proxied. If you intend to proxy a IFactoryObject instance itself
/// specify the object name of the IFactoryObject including
/// the factory-object prefix "&amp;" e.g. "&amp;MyFactoryObject".
/// </para>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator.IsMatch"/>
/// <author>Juergen Hoeller</author>
/// <author>Adhari C Mahendra (.NET)</author>
/// <version>$Id: ObjectNameAutoProxyCreator.cs,v 1.8 2008/03/03 09:28:49 bbaia Exp $</version>
public class ObjectNameAutoProxyCreator : AbstractAutoProxyCreator
{
private IList objectNames;
/// <summary>
/// Set the names of the objects in IList fashioned way that should automatically
/// get wrapped with proxies.
/// A name can specify a prefix to match by ending with "*", e.g. "myObject,tx*"
/// will match the object named "myObject" and all objects whose name start with "tx".
/// </summary>
public IList ObjectNames
{
set { objectNames = value; }
}
/// <summary>
/// Identify as object to proxy if the object name is in the configured list of names.
/// </summary>
protected override object[] GetAdvicesAndAdvisorsForObject(Type objType, string name, ITargetSource customTargetSource)
{
if (objectNames != null)
{
for (int i = 0; i < objectNames.Count; i++)
{
string mappedName = String.Copy((string) objectNames[i]);
if (typeof (IFactoryObject).IsAssignableFrom(objType))
{
if (!name.StartsWith(ObjectFactoryUtils.FactoryObjectPrefix))
{
continue;
}
mappedName = mappedName.Substring(ObjectFactoryUtils.FactoryObjectPrefix.Length);
}
if (IsMatch(name, mappedName))
{
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
}
}
}
return DO_NOT_PROXY;
}
/// <summary>
/// Return if the given object name matches the mapped name.
/// </summary>
/// <remarks>
/// <p>
/// The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
/// as well as direct equality. Can be overridden in subclasses.
/// </p>
/// </remarks>
/// <param name="objectName">the object name to check</param>
/// <param name="mappedName">the name in the configured list of names</param>
/// <returns>if the names match</returns>
protected virtual bool IsMatch(string objectName, string mappedName)
{
return PatternMatchUtils.SimpleMatch(mappedName, objectName);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using Spring.Objects.Factory;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Object Auto Proxy Creator
/// </summary>
/// <remarks>
/// <para>
/// Auto proxy creator that identifies objects to proxy via a list of names.
/// Checks for direct, "xxx*", "*xxx" and "*xxx*" matches.
/// </para>
/// <para>In case of a IFactoryObject, only the objects created by the
/// FactoryBean will get proxied. If you intend to proxy a IFactoryObject instance itself
/// specify the object name of the IFactoryObject including
/// the factory-object prefix "&amp;" e.g. "&amp;MyFactoryObject".
/// </para>
/// </remarks>
/// <seealso cref="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator.IsMatch"/>
/// <author>Juergen Hoeller</author>
/// <author>Adhari C Mahendra (.NET)</author>
public class ObjectNameAutoProxyCreator : AbstractAutoProxyCreator
{
private IList objectNames;
/// <summary>
/// Set the names of the objects in IList fashioned way that should automatically
/// get wrapped with proxies.
/// A name can specify a prefix to match by ending with "*", e.g. "myObject,tx*"
/// will match the object named "myObject" and all objects whose name start with "tx".
/// </summary>
public IList ObjectNames
{
set { objectNames = value; }
}
/// <summary>
/// Identify as object to proxy if the object name is in the configured list of names.
/// </summary>
protected override object[] GetAdvicesAndAdvisorsForObject(Type objType, string name, ITargetSource customTargetSource)
{
if (objectNames != null)
{
for (int i = 0; i < objectNames.Count; i++)
{
string mappedName = String.Copy((string) objectNames[i]);
if (typeof (IFactoryObject).IsAssignableFrom(objType))
{
if (!name.StartsWith(ObjectFactoryUtils.FactoryObjectPrefix))
{
continue;
}
mappedName = mappedName.Substring(ObjectFactoryUtils.FactoryObjectPrefix.Length);
}
if (IsMatch(name, mappedName))
{
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
}
}
}
return DO_NOT_PROXY;
}
/// <summary>
/// Return if the given object name matches the mapped name.
/// </summary>
/// <remarks>
/// <p>
/// The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
/// as well as direct equality. Can be overridden in subclasses.
/// </p>
/// </remarks>
/// <param name="objectName">the object name to check</param>
/// <param name="mappedName">the name in the configured list of names</param>
/// <returns>if the names match</returns>
protected virtual bool IsMatch(string objectName, string mappedName)
{
return PatternMatchUtils.SimpleMatch(mappedName, objectName);
}
}
}

View File

@@ -1,107 +1,107 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Common.Logging;
using Spring.Aop.Target;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Support;
#endregion
namespace Spring.Aop.Framework.AutoProxy.Target
{
/// <summary>
/// Summary description for AbstractPrototypeBasedTargetSourceCreator.
/// </summary>
public abstract class AbstractPrototypeTargetSourceCreator : ITargetSourceCreator
{
/// <summary>
/// The logger
/// </summary>
protected readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region ITargetSourceCreator Members
/// <summary>
/// Create a special TargetSource for the given object, if any.
/// </summary>
/// <param name="objectType">the type of the object to create a TargetSource for</param>
/// <param name="name">the name of the object</param>
/// <param name="factory">the containing factory</param>
/// <returns>
/// a special TargetSource or null if this TargetSourceCreator isn't
/// interested in the particular object
/// </returns>
public ITargetSource GetTargetSource(Type objectType, string name, IObjectFactory factory)
{
AbstractPrototypeTargetSource prototypeTargetSource = CreatePrototypeTargetSource(objectType, name, factory);
if (prototypeTargetSource == null)
{
return null;
}
else
{
if (!(factory is IObjectDefinitionRegistry))
{
if (logger.IsWarnEnabled)
logger.Warn("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry");
return null;
}
IObjectDefinitionRegistry definitionRegistry = (IObjectDefinitionRegistry) factory;
RootObjectDefinition definition = (RootObjectDefinition) definitionRegistry.GetObjectDefinition(name);
if (logger.IsInfoEnabled)
logger.Info("Configuring AbstractPrototypeBasedTargetSource...");
// Infinite cycle will result if we don't use a different factory,
// because a GetObject() call with this objectName will go through the autoproxy
// infrastructure again.
// We to override just this object definition, as it may reference other objects
// and we're happy to take the parent's definition for those.
DefaultListableObjectFactory objectFactory = new DefaultListableObjectFactory(factory);
// Override the prototype object
objectFactory.RegisterObjectDefinition(name, definition);
// Complete configuring the PrototypeTargetSource
prototypeTargetSource.TargetObjectName = name;
prototypeTargetSource.ObjectFactory = objectFactory;
return prototypeTargetSource;
}
}
#endregion
/// <summary>
/// Creates the prototype target source.
/// </summary>
/// <param name="objectType">The type of the object to create a target source for.</param>
/// <param name="name">The name.</param>
/// <param name="factory">The factory.</param>
/// <returns></returns>
protected abstract AbstractPrototypeTargetSource CreatePrototypeTargetSource(Type objectType, string name,
IObjectFactory factory);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Common.Logging;
using Spring.Aop.Target;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Support;
#endregion
namespace Spring.Aop.Framework.AutoProxy.Target
{
/// <summary>
/// Summary description for AbstractPrototypeBasedTargetSourceCreator.
/// </summary>
public abstract class AbstractPrototypeTargetSourceCreator : ITargetSourceCreator
{
/// <summary>
/// The logger
/// </summary>
protected readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region ITargetSourceCreator Members
/// <summary>
/// Create a special TargetSource for the given object, if any.
/// </summary>
/// <param name="objectType">the type of the object to create a TargetSource for</param>
/// <param name="name">the name of the object</param>
/// <param name="factory">the containing factory</param>
/// <returns>
/// a special TargetSource or null if this TargetSourceCreator isn't
/// interested in the particular object
/// </returns>
public ITargetSource GetTargetSource(Type objectType, string name, IObjectFactory factory)
{
AbstractPrototypeTargetSource prototypeTargetSource = CreatePrototypeTargetSource(objectType, name, factory);
if (prototypeTargetSource == null)
{
return null;
}
else
{
if (!(factory is IObjectDefinitionRegistry))
{
if (logger.IsWarnEnabled)
logger.Warn("Cannot do autopooling with a IObjectFactory that doesn't implement IObjectDefinitionRegistry");
return null;
}
IObjectDefinitionRegistry definitionRegistry = (IObjectDefinitionRegistry) factory;
RootObjectDefinition definition = (RootObjectDefinition) definitionRegistry.GetObjectDefinition(name);
if (logger.IsInfoEnabled)
logger.Info("Configuring AbstractPrototypeBasedTargetSource...");
// Infinite cycle will result if we don't use a different factory,
// because a GetObject() call with this objectName will go through the autoproxy
// infrastructure again.
// We to override just this object definition, as it may reference other objects
// and we're happy to take the parent's definition for those.
DefaultListableObjectFactory objectFactory = new DefaultListableObjectFactory(factory);
// Override the prototype object
objectFactory.RegisterObjectDefinition(name, definition);
// Complete configuring the PrototypeTargetSource
prototypeTargetSource.TargetObjectName = name;
prototypeTargetSource.ObjectFactory = objectFactory;
return prototypeTargetSource;
}
}
#endregion
/// <summary>
/// Creates the prototype target source.
/// </summary>
/// <param name="objectType">The type of the object to create a target source for.</param>
/// <param name="name">The name.</param>
/// <param name="factory">The factory.</param>
/// <returns></returns>
protected abstract AbstractPrototypeTargetSource CreatePrototypeTargetSource(Type objectType, string name,
IObjectFactory factory);
}
}

View File

@@ -1,126 +1,125 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using Spring.Util;
using Spring.Reflection.Dynamic;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Invokes a target method using dynamic reflection.
/// </summary>
/// <seealso cref="Spring.Reflection.Dynamic.DynamicMethod"/>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
/// <version>$Id: DynamicMethodInvocation.cs,v 1.3 2008/02/06 18:28:52 bbaia Exp $</version>
[Serializable]
public class DynamicMethodInvocation : AbstractMethodInvocation
{
/// <summary>
/// The method invocation that is to be invoked on the proxy.
/// </summary>
protected MethodInfo proxyMethod;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicMethodInvocation"/> class.
/// </summary>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">The target method proxied.</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If any of the <paramref name="target"/> or <paramref name="method"/>
/// parameters is <see langword="null"/>.
/// </exception>
public DynamicMethodInvocation(
object proxy, object target, MethodInfo method, MethodInfo proxyMethod,
object[] arguments, Type targetType, IList interceptors)
: base(proxy, target, method, arguments, targetType, interceptors)
{
this.proxyMethod = proxyMethod;
}
/// <summary>
/// Invokes the joinpoint using dynamic reflection.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/>
protected override object InvokeJoinpoint()
{
IDynamicMethod targetMethod = (this.proxyMethod == null) ? new SafeMethod(method) : new SafeMethod(proxyMethod);
try
{
return targetMethod.Invoke(target, arguments);
}
// Only happens if fallback to standard reflection.
catch (TargetInvocationException ex)
{
throw ReflectionUtils.UnwrapTargetInvocationException(ex);
}
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.Framework.DynamicMethodInvocation"/> instance
/// from the specified <see cref="AopAlliance.Intercept.IMethodInvocation"/> and
/// increments the interceptor index.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
protected override IMethodInvocation PrepareMethodInvocationForProceed(IMethodInvocation invocation)
{
DynamicMethodInvocation rmi = new DynamicMethodInvocation(
this.proxy, this.target, this.method, this.proxyMethod, this.arguments, this.targetType, this.interceptors);
rmi.currentInterceptorIndex = this.currentInterceptorIndex + 1;
return rmi;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using Spring.Util;
using Spring.Reflection.Dynamic;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Invokes a target method using dynamic reflection.
/// </summary>
/// <seealso cref="Spring.Reflection.Dynamic.DynamicMethod"/>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
[Serializable]
public class DynamicMethodInvocation : AbstractMethodInvocation
{
/// <summary>
/// The method invocation that is to be invoked on the proxy.
/// </summary>
protected MethodInfo proxyMethod;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicMethodInvocation"/> class.
/// </summary>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">The target method proxied.</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If any of the <paramref name="target"/> or <paramref name="method"/>
/// parameters is <see langword="null"/>.
/// </exception>
public DynamicMethodInvocation(
object proxy, object target, MethodInfo method, MethodInfo proxyMethod,
object[] arguments, Type targetType, IList interceptors)
: base(proxy, target, method, arguments, targetType, interceptors)
{
this.proxyMethod = proxyMethod;
}
/// <summary>
/// Invokes the joinpoint using dynamic reflection.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/>
protected override object InvokeJoinpoint()
{
IDynamicMethod targetMethod = (this.proxyMethod == null) ? new SafeMethod(method) : new SafeMethod(proxyMethod);
try
{
return targetMethod.Invoke(target, arguments);
}
// Only happens if fallback to standard reflection.
catch (TargetInvocationException ex)
{
throw ReflectionUtils.UnwrapTargetInvocationException(ex);
}
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.Framework.DynamicMethodInvocation"/> instance
/// from the specified <see cref="AopAlliance.Intercept.IMethodInvocation"/> and
/// increments the interceptor index.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
protected override IMethodInvocation PrepareMethodInvocationForProceed(IMethodInvocation invocation)
{
DynamicMethodInvocation rmi = new DynamicMethodInvocation(
this.proxy, this.target, this.method, this.proxyMethod, this.arguments, this.targetType, this.interceptors);
rmi.currentInterceptorIndex = this.currentInterceptorIndex + 1;
return rmi;
}
}
}

View File

@@ -1,106 +1,105 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection.Emit;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Base class for proxy builders that can be used
/// to create an AOP proxy for any object.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: AbstractAopProxyTypeBuilder.cs,v 1.5 2007/12/03 09:06:58 bbaia Exp $</version>
public abstract class AbstractAopProxyTypeBuilder :
AbstractProxyTypeBuilder, IAopProxyTypeGenerator
{
#region IProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushTarget(ILGenerator il)
{
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.TargetSourceWrapperField);
il.EmitCall(OpCodes.Callvirt, References.GetTargetMethod, null);
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public abstract void PushAdvisedProxy(ILGenerator il);
#endregion
#region Protected Methods
/// <summary>
/// Calculates and returns the list of attributes that apply to the
/// specified type.
/// </summary>
/// <remarks>
/// Removes <see cref="System.SerializableAttribute"/> from the list.
/// </remarks>
/// <param name="type">The type to find attributes for.</param>
/// <returns>
/// A list of custom attributes that should be applied to type.
/// </returns>
protected override IList GetTypeAttributes(Type type)
{
IList attrs = base.GetTypeAttributes(type);
int i = 0;
while (i < attrs.Count)
{
if (IsAttributeMatchingType(attrs[i], typeof(SerializableAttribute)))
{
attrs.RemoveAt(i);
}
else
{
i++;
}
}
return attrs;
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection.Emit;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Base class for proxy builders that can be used
/// to create an AOP proxy for any object.
/// </summary>
/// <author>Bruno Baia</author>
public abstract class AbstractAopProxyTypeBuilder :
AbstractProxyTypeBuilder, IAopProxyTypeGenerator
{
#region IProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushTarget(ILGenerator il)
{
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.TargetSourceWrapperField);
il.EmitCall(OpCodes.Callvirt, References.GetTargetMethod, null);
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public abstract void PushAdvisedProxy(ILGenerator il);
#endregion
#region Protected Methods
/// <summary>
/// Calculates and returns the list of attributes that apply to the
/// specified type.
/// </summary>
/// <remarks>
/// Removes <see cref="System.SerializableAttribute"/> from the list.
/// </remarks>
/// <param name="type">The type to find attributes for.</param>
/// <returns>
/// A list of custom attributes that should be applied to type.
/// </returns>
protected override IList GetTypeAttributes(Type type)
{
IList attrs = base.GetTypeAttributes(type);
int i = 0;
while (i < attrs.Count)
{
if (IsAttributeMatchingType(attrs[i], typeof(SerializableAttribute)))
{
attrs.RemoveAt(i);
}
else
{
i++;
}
}
return attrs;
}
#endregion
}
}

View File

@@ -1,432 +1,431 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security.Permissions;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Represents the AOP configuration data built-in with the proxy.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: AdvisedProxy.cs,v 1.10 2008/02/06 18:28:52 bbaia Exp $</version>
[Serializable]
public class AdvisedProxy : IAdvised //, ISerializable
{
#region Fields
/// <summary>
/// Should we use dynamic reflection for method invocation ?
/// </summary>
public static bool UseDynamicReflection;
/// <summary>
/// Optimization fields
/// </summary>
private static IList EmptyList = ArrayList.ReadOnly(new ArrayList());
/// <summary>
/// IAdvised delegate
/// </summary>
public IAdvised m_advised;
/// <summary>
/// Array of introduction delegates
/// </summary>
public IAdvice[] m_introductions;
/// <summary>
/// Target source wrapper
/// </summary>
public ITargetSourceWrapper m_targetSourceWrapper;
/// <summary>
/// Type of target object.
/// </summary>
public Type m_targetType;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
static AdvisedProxy()
{
string appSettingsKey = typeof(AdvisedProxy).FullName + ".UseDynamicReflection";
NameValueCollection appSettings =
ConfigurationUtils.GetSection("appSettings") as NameValueCollection;
if (appSettings != null && StringUtils.HasLength(appSettings[appSettingsKey]))
{
UseDynamicReflection = bool.Parse(appSettings[appSettingsKey]);
}
else
{
UseDynamicReflection = true;
}
}
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
public AdvisedProxy()
{}
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
protected AdvisedProxy(IAdvised advised)
{
m_advised = advised;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
/// <param name="proxy">The proxy.</param>
public AdvisedProxy(IAdvised advised, IAopProxy proxy)
{
Initialize(advised, proxy);
}
/// <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_targetSourceWrapper = (ITargetSourceWrapper) info.GetValue("tsWrapper", typeof(ITargetSourceWrapper));
m_targetType = (Type) info.GetValue("targetType", typeof(Type));
}
/// <summary>
/// Serializes this instance.
/// </summary>
/// <param name="info">Serialization data.</param>
/// <param name="context">Serialization context.</param>
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("advised", m_advised);
info.AddValue("introductions", m_introductions);
info.AddValue("tsWrapper", m_targetSourceWrapper);
info.AddValue("targetType", m_targetType);
}
#endregion
#region Protected Methods
/// <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_targetType = advised.TargetSource.TargetType;
// initialize target
if (advised.TargetSource.IsStatic)
{
this.m_targetSourceWrapper = new StaticTargetSourceWrapper(advised.TargetSource);
}
else
{
this.m_targetSourceWrapper = new DynamicTargetSourceWrapper(advised.TargetSource);
}
// initialize introduction advice
this.m_introductions = new IAdvice[advised.Introductions.Length];
for (int i = 0; i < advised.Introductions.Length; 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;
}
}
}
#endregion
#region Public Methods
/// <summary>
/// Invokes intercepted methods using reflection
/// </summary>
/// <param name="proxy">proxy object</param>
/// <param name="target">target object to invoke method on</param>
/// <param name="targetType">target type</param>
/// <param name="targetMethod">taget method to invoke</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="args">method arguments</param>
/// <param name="interceptors">interceptor chain</param>
/// <returns>value returned by invocation chain</returns>
public object Invoke(object proxy, object target, Type targetType,
MethodInfo targetMethod, MethodInfo proxyMethod, object[] args, IList interceptors)
{
IMethodInvocation invocation = null;
if (UseDynamicReflection)
{
invocation = new DynamicMethodInvocation(
proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
else
{
invocation = new ReflectiveMethodInvocation(
proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
return invocation.Proceed();
}
/// <summary>
/// Returns a list of method interceptors
/// </summary>
/// <param name="targetType">target type</param>
/// <param name="method">target method</param>
/// <returns>list of inteceptors for the specified method</returns>
public IList GetInterceptors(Type targetType, MethodInfo method)
{
if (m_advised.Advisors.Length == 0)
{
return EmptyList;
}
else
{
return m_advised.AdvisorChainFactory.GetInterceptors(m_advised, this, method, targetType);
}
}
#endregion
#region IAdvised Members
bool IAdvised.ExposeProxy
{
get { return m_advised.ExposeProxy; }
}
IAdvisorChainFactory IAdvised.AdvisorChainFactory
{
get { return m_advised.AdvisorChainFactory; }
}
bool IAdvised.ProxyTargetType
{
get { return m_advised.ProxyTargetType; }
}
bool IAdvised.ProxyTargetAttributes
{
get { return m_advised.ProxyTargetAttributes; }
}
IAdvisor[] IAdvised.Advisors
{
get { return m_advised.Advisors; }
}
IIntroductionAdvisor[] IAdvised.Introductions
{
get { return m_advised.Introductions; }
}
Type[] IAdvised.Interfaces
{
get { return m_advised.Interfaces; }
}
IDictionary IAdvised.InterfaceMap
{
get { return m_advised.InterfaceMap; }
}
bool IAdvised.IsFrozen
{
get { return m_advised.IsFrozen; }
}
ITargetSource IAdvised.TargetSource
{
get { return m_advised.TargetSource; }
}
bool IAdvised.IsSerializable
{
get { return m_advised.IsSerializable; }
}
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the end (or tail)
/// of the advice (interceptor) chain.
/// </summary>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(int,IAdvice)"/>
public void AddAdvice(IAdvice advice)
{
this.m_advised.AddAdvice(advice);
}
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the supplied
/// <paramref name="position"/> in the advice (interceptor) chain.
/// </summary>
/// <param name="position">
/// The zero (0) indexed position (from the head) at which the
/// supplied <paramref name="advice"/> is to be inserted into the
/// advice (interceptor) chain.
/// </param>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(IAdvice)"/>
public void AddAdvice(int position, IAdvice advice)
{
this.m_advised.AddAdvice(position, advice);
}
bool IAdvised.IsInterfaceProxied(Type intf)
{
return m_advised.IsInterfaceProxied(intf);
}
void IAdvised.AddAdvisors(IAdvisors advisors)
{
m_advised.AddAdvisors(advisors);
}
void IAdvised.AddAdvisor(IAdvisor advisor)
{
m_advised.AddAdvisor(advisor);
}
void IAdvised.AddAdvisor(int pos, IAdvisor advisor)
{
m_advised.AddAdvisor(pos, advisor);
}
void IAdvised.AddIntroduction(IIntroductionAdvisor advisor)
{
m_advised.AddIntroduction(advisor);
}
void IAdvised.AddIntroduction(int pos, IIntroductionAdvisor advisor)
{
m_advised.AddIntroduction(pos, advisor);
}
int IAdvised.IndexOf(IAdvisor advisor)
{
return m_advised.IndexOf(advisor);
}
int IAdvised.IndexOf(IIntroductionAdvisor advisor)
{
return m_advised.IndexOf(advisor);
}
bool IAdvised.RemoveAdvisor(IAdvisor advisor)
{
return m_advised.RemoveAdvisor(advisor);
}
void IAdvised.RemoveAdvisor(int index)
{
m_advised.RemoveAdvisor(index);
}
bool IAdvised.RemoveAdvice(IAdvice advice)
{
return m_advised.RemoveAdvice(advice);
}
bool IAdvised.RemoveIntroduction(IIntroductionAdvisor advisor)
{
return m_advised.RemoveIntroduction(advisor);
}
void IAdvised.RemoveIntroduction(int index)
{
m_advised.RemoveIntroduction(index);
}
void IAdvised.ReplaceIntroduction(int index, IIntroductionAdvisor advisor)
{
m_advised.ReplaceIntroduction(index, advisor);
}
bool IAdvised.ReplaceAdvisor(IAdvisor a, IAdvisor b)
{
return m_advised.ReplaceAdvisor(a, b);
}
string IAdvised.ToProxyConfigString()
{
return m_advised.ToProxyConfigString();
}
#endregion
#region ITargetTypeAware implementation
/// <summary>
/// Gets the target type behind the implementing object.
/// Ttypically a proxy configuration or an actual proxy.
/// </summary>
/// <value>The type of the target or null if not known.</value>
public Type TargetType
{
get { return m_targetType; }
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security.Permissions;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Represents the AOP configuration data built-in with the proxy.
/// </summary>
/// <author>Bruno Baia</author>
[Serializable]
public class AdvisedProxy : IAdvised //, ISerializable
{
#region Fields
/// <summary>
/// Should we use dynamic reflection for method invocation ?
/// </summary>
public static bool UseDynamicReflection;
/// <summary>
/// Optimization fields
/// </summary>
private static IList EmptyList = ArrayList.ReadOnly(new ArrayList());
/// <summary>
/// IAdvised delegate
/// </summary>
public IAdvised m_advised;
/// <summary>
/// Array of introduction delegates
/// </summary>
public IAdvice[] m_introductions;
/// <summary>
/// Target source wrapper
/// </summary>
public ITargetSourceWrapper m_targetSourceWrapper;
/// <summary>
/// Type of target object.
/// </summary>
public Type m_targetType;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
static AdvisedProxy()
{
string appSettingsKey = typeof(AdvisedProxy).FullName + ".UseDynamicReflection";
NameValueCollection appSettings =
ConfigurationUtils.GetSection("appSettings") as NameValueCollection;
if (appSettings != null && StringUtils.HasLength(appSettings[appSettingsKey]))
{
UseDynamicReflection = bool.Parse(appSettings[appSettingsKey]);
}
else
{
UseDynamicReflection = true;
}
}
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
public AdvisedProxy()
{}
/// <summary>
/// Creates a new instance of the <see cref="AdvisedProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
protected AdvisedProxy(IAdvised advised)
{
m_advised = advised;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
/// <param name="proxy">The proxy.</param>
public AdvisedProxy(IAdvised advised, IAopProxy proxy)
{
Initialize(advised, proxy);
}
/// <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_targetSourceWrapper = (ITargetSourceWrapper) info.GetValue("tsWrapper", typeof(ITargetSourceWrapper));
m_targetType = (Type) info.GetValue("targetType", typeof(Type));
}
/// <summary>
/// Serializes this instance.
/// </summary>
/// <param name="info">Serialization data.</param>
/// <param name="context">Serialization context.</param>
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("advised", m_advised);
info.AddValue("introductions", m_introductions);
info.AddValue("tsWrapper", m_targetSourceWrapper);
info.AddValue("targetType", m_targetType);
}
#endregion
#region Protected Methods
/// <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_targetType = advised.TargetSource.TargetType;
// initialize target
if (advised.TargetSource.IsStatic)
{
this.m_targetSourceWrapper = new StaticTargetSourceWrapper(advised.TargetSource);
}
else
{
this.m_targetSourceWrapper = new DynamicTargetSourceWrapper(advised.TargetSource);
}
// initialize introduction advice
this.m_introductions = new IAdvice[advised.Introductions.Length];
for (int i = 0; i < advised.Introductions.Length; 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;
}
}
}
#endregion
#region Public Methods
/// <summary>
/// Invokes intercepted methods using reflection
/// </summary>
/// <param name="proxy">proxy object</param>
/// <param name="target">target object to invoke method on</param>
/// <param name="targetType">target type</param>
/// <param name="targetMethod">taget method to invoke</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="args">method arguments</param>
/// <param name="interceptors">interceptor chain</param>
/// <returns>value returned by invocation chain</returns>
public object Invoke(object proxy, object target, Type targetType,
MethodInfo targetMethod, MethodInfo proxyMethod, object[] args, IList interceptors)
{
IMethodInvocation invocation = null;
if (UseDynamicReflection)
{
invocation = new DynamicMethodInvocation(
proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
else
{
invocation = new ReflectiveMethodInvocation(
proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
return invocation.Proceed();
}
/// <summary>
/// Returns a list of method interceptors
/// </summary>
/// <param name="targetType">target type</param>
/// <param name="method">target method</param>
/// <returns>list of inteceptors for the specified method</returns>
public IList GetInterceptors(Type targetType, MethodInfo method)
{
if (m_advised.Advisors.Length == 0)
{
return EmptyList;
}
else
{
return m_advised.AdvisorChainFactory.GetInterceptors(m_advised, this, method, targetType);
}
}
#endregion
#region IAdvised Members
bool IAdvised.ExposeProxy
{
get { return m_advised.ExposeProxy; }
}
IAdvisorChainFactory IAdvised.AdvisorChainFactory
{
get { return m_advised.AdvisorChainFactory; }
}
bool IAdvised.ProxyTargetType
{
get { return m_advised.ProxyTargetType; }
}
bool IAdvised.ProxyTargetAttributes
{
get { return m_advised.ProxyTargetAttributes; }
}
IAdvisor[] IAdvised.Advisors
{
get { return m_advised.Advisors; }
}
IIntroductionAdvisor[] IAdvised.Introductions
{
get { return m_advised.Introductions; }
}
Type[] IAdvised.Interfaces
{
get { return m_advised.Interfaces; }
}
IDictionary IAdvised.InterfaceMap
{
get { return m_advised.InterfaceMap; }
}
bool IAdvised.IsFrozen
{
get { return m_advised.IsFrozen; }
}
ITargetSource IAdvised.TargetSource
{
get { return m_advised.TargetSource; }
}
bool IAdvised.IsSerializable
{
get { return m_advised.IsSerializable; }
}
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the end (or tail)
/// of the advice (interceptor) chain.
/// </summary>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(int,IAdvice)"/>
public void AddAdvice(IAdvice advice)
{
this.m_advised.AddAdvice(advice);
}
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the supplied
/// <paramref name="position"/> in the advice (interceptor) chain.
/// </summary>
/// <param name="position">
/// The zero (0) indexed position (from the head) at which the
/// supplied <paramref name="advice"/> is to be inserted into the
/// advice (interceptor) chain.
/// </param>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(IAdvice)"/>
public void AddAdvice(int position, IAdvice advice)
{
this.m_advised.AddAdvice(position, advice);
}
bool IAdvised.IsInterfaceProxied(Type intf)
{
return m_advised.IsInterfaceProxied(intf);
}
void IAdvised.AddAdvisors(IAdvisors advisors)
{
m_advised.AddAdvisors(advisors);
}
void IAdvised.AddAdvisor(IAdvisor advisor)
{
m_advised.AddAdvisor(advisor);
}
void IAdvised.AddAdvisor(int pos, IAdvisor advisor)
{
m_advised.AddAdvisor(pos, advisor);
}
void IAdvised.AddIntroduction(IIntroductionAdvisor advisor)
{
m_advised.AddIntroduction(advisor);
}
void IAdvised.AddIntroduction(int pos, IIntroductionAdvisor advisor)
{
m_advised.AddIntroduction(pos, advisor);
}
int IAdvised.IndexOf(IAdvisor advisor)
{
return m_advised.IndexOf(advisor);
}
int IAdvised.IndexOf(IIntroductionAdvisor advisor)
{
return m_advised.IndexOf(advisor);
}
bool IAdvised.RemoveAdvisor(IAdvisor advisor)
{
return m_advised.RemoveAdvisor(advisor);
}
void IAdvised.RemoveAdvisor(int index)
{
m_advised.RemoveAdvisor(index);
}
bool IAdvised.RemoveAdvice(IAdvice advice)
{
return m_advised.RemoveAdvice(advice);
}
bool IAdvised.RemoveIntroduction(IIntroductionAdvisor advisor)
{
return m_advised.RemoveIntroduction(advisor);
}
void IAdvised.RemoveIntroduction(int index)
{
m_advised.RemoveIntroduction(index);
}
void IAdvised.ReplaceIntroduction(int index, IIntroductionAdvisor advisor)
{
m_advised.ReplaceIntroduction(index, advisor);
}
bool IAdvised.ReplaceAdvisor(IAdvisor a, IAdvisor b)
{
return m_advised.ReplaceAdvisor(a, b);
}
string IAdvised.ToProxyConfigString()
{
return m_advised.ToProxyConfigString();
}
#endregion
#region ITargetTypeAware implementation
/// <summary>
/// Gets the target type behind the implementing object.
/// Ttypically a proxy configuration or an actual proxy.
/// </summary>
/// <value>The type of the target or null if not known.</value>
public Type TargetType
{
get { return m_targetType; }
}
#endregion
}
}

View File

@@ -1,131 +1,130 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to the base method.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: BaseAopProxyMethodBuilder.cs,v 1.1 2008/02/06 18:28:52 bbaia Exp $</version>
public class BaseAopProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="targetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s.
/// </param>
/// <param name="onProxyTargetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s defined on the proxy.
/// </param>
public BaseAopProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
IDictionary targetMethods, IDictionary onProxyTargetMethods)
: base(typeBuilder, aopProxyGenerator, false, targetMethods, onProxyTargetMethods)
{
}
#endregion
#region Protected Methods
/// <summary>
/// Create static field that will cache target method when defined on the proxy.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The target method.</param>
protected override void GenerateOnProxyTargetMethodCacheField(
ILGenerator il, MethodInfo method)
{
if (method.IsVirtual && !method.IsFinal)
{
// generate proxy method
MethodBuilder baseMethod = typeBuilder.DefineMethod("proxy_" + method.Name,
MethodAttributes.Public | MethodAttributes.HideBySig,
CallingConventions.Standard,
method.ReturnType, ReflectionUtils.GetParameterTypes(method));
#if NET_2_0
DefineGenericParameters(baseMethod, method);
#endif
DefineParameters(baseMethod, method);
ILGenerator localIL = baseMethod.GetILGenerator();
localIL.Emit(OpCodes.Ldarg_0);
// setup parameters for call
for (int i = 0; i < method.GetParameters().Length; i++)
{
localIL.Emit(OpCodes.Ldarg_S, i + 1);
}
localIL.EmitCall(OpCodes.Call, method, null);
localIL.Emit(OpCodes.Ret);
// create static field that will cache proxy method
string methodId = GenerateMethodCacheFieldId(method);
onProxyTargetMethods.Add(methodId, method);
onProxyTargetMethodCacheField = typeBuilder.DefineField(
methodId, typeof(MethodInfo), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
#if NET_2_0
MakeGenericMethod(il, method, onProxyTargetMethodCacheField, genericOnProxyTargetMethod);
#endif
}
}
/// <summary>
/// Calls target method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
CallDirectBaseMethod(il, method);
}
#endregion
}
}
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to the base method.
/// </summary>
/// <author>Bruno Baia</author>
public class BaseAopProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="targetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s.
/// </param>
/// <param name="onProxyTargetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s defined on the proxy.
/// </param>
public BaseAopProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
IDictionary targetMethods, IDictionary onProxyTargetMethods)
: base(typeBuilder, aopProxyGenerator, false, targetMethods, onProxyTargetMethods)
{
}
#endregion
#region Protected Methods
/// <summary>
/// Create static field that will cache target method when defined on the proxy.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The target method.</param>
protected override void GenerateOnProxyTargetMethodCacheField(
ILGenerator il, MethodInfo method)
{
if (method.IsVirtual && !method.IsFinal)
{
// generate proxy method
MethodBuilder baseMethod = typeBuilder.DefineMethod("proxy_" + method.Name,
MethodAttributes.Public | MethodAttributes.HideBySig,
CallingConventions.Standard,
method.ReturnType, ReflectionUtils.GetParameterTypes(method));
#if NET_2_0
DefineGenericParameters(baseMethod, method);
#endif
DefineParameters(baseMethod, method);
ILGenerator localIL = baseMethod.GetILGenerator();
localIL.Emit(OpCodes.Ldarg_0);
// setup parameters for call
for (int i = 0; i < method.GetParameters().Length; i++)
{
localIL.Emit(OpCodes.Ldarg_S, i + 1);
}
localIL.EmitCall(OpCodes.Call, method, null);
localIL.Emit(OpCodes.Ret);
// create static field that will cache proxy method
string methodId = GenerateMethodCacheFieldId(method);
onProxyTargetMethods.Add(methodId, method);
onProxyTargetMethodCacheField = typeBuilder.DefineField(
methodId, typeof(MethodInfo), FieldAttributes.Private | FieldAttributes.Static | FieldAttributes.InitOnly);
#if NET_2_0
MakeGenericMethod(il, method, onProxyTargetMethodCacheField, genericOnProxyTargetMethod);
#endif
}
}
/// <summary>
/// Calls target method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
CallDirectBaseMethod(il, method);
}
#endregion
}
}

View File

@@ -1,122 +1,121 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Base class that each dynamic composition proxy has to extend.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
/// <version>$Id: BaseCompositionAopProxy.cs,v 1.2 2007/03/16 04:01:22 aseovic Exp $</version>
[Serializable]
public abstract class BaseCompositionAopProxy : AdvisedProxy, IAopProxy, ISerializable
{
#region Constructor (s) / Destructor
/// <summary>
/// Default constructor.
/// </summary>
public BaseCompositionAopProxy()
{}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicProxy.BaseCompositionAopProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public BaseCompositionAopProxy(IAdvised advised) : base(advised)
{
base.Initialize(advised, this);
}
/// <summary>
/// Deserialization constructor.
/// </summary>
/// <param name="info">Serialization data.</param>
/// <param name="context">Serialization context.</param>
protected BaseCompositionAopProxy(SerializationInfo info, StreamingContext context) : base(info, context)
{}
#endregion
#region IAopProxy Members
/// <summary>
/// Returns this proxy instance
/// </summary>
/// <returns></returns>
object IAopProxy.GetProxy()
{
return this;
}
#endregion
#region Equal, HashCode and ToString overrides
/// <summary>
/// Delegate to target object handling of equals method.
/// </summary>
/// <param name="obj">The object to compare with the current target object</param>
/// <returns>true if the specified Object is equal to the current target object; otherwise, false</returns>
public override bool Equals(object obj)
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().Equals(obj);
}
}
/// <summary>
/// Delgate to the target object generation of the hash code.
/// </summary>
/// <returns>A hash code for the target object.</returns>
public override int GetHashCode()
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().GetHashCode();
}
}
/// <summary>
/// Returns a String the represents the target object.
/// </summary>
/// <returns>A String that represents the target object</returns>
public override string ToString()
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().ToString();
}
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Base class that each dynamic composition proxy has to extend.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
[Serializable]
public abstract class BaseCompositionAopProxy : AdvisedProxy, IAopProxy, ISerializable
{
#region Constructor (s) / Destructor
/// <summary>
/// Default constructor.
/// </summary>
public BaseCompositionAopProxy()
{}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.DynamicProxy.BaseCompositionAopProxy"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public BaseCompositionAopProxy(IAdvised advised) : base(advised)
{
base.Initialize(advised, this);
}
/// <summary>
/// Deserialization constructor.
/// </summary>
/// <param name="info">Serialization data.</param>
/// <param name="context">Serialization context.</param>
protected BaseCompositionAopProxy(SerializationInfo info, StreamingContext context) : base(info, context)
{}
#endregion
#region IAopProxy Members
/// <summary>
/// Returns this proxy instance
/// </summary>
/// <returns></returns>
object IAopProxy.GetProxy()
{
return this;
}
#endregion
#region Equal, HashCode and ToString overrides
/// <summary>
/// Delegate to target object handling of equals method.
/// </summary>
/// <param name="obj">The object to compare with the current target object</param>
/// <returns>true if the specified Object is equal to the current target object; otherwise, false</returns>
public override bool Equals(object obj)
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().Equals(obj);
}
}
/// <summary>
/// Delgate to the target object generation of the hash code.
/// </summary>
/// <returns>A hash code for the target object.</returns>
public override int GetHashCode()
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().GetHashCode();
}
}
/// <summary>
/// Returns a String the represents the target object.
/// </summary>
/// <returns>A String that represents the target object</returns>
public override string ToString()
{
using (m_targetSourceWrapper)
{
return m_targetSourceWrapper.GetTarget().ToString();
}
}
#endregion
}
}

View File

@@ -1,184 +1,183 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Text;
using System.Collections;
using Common.Logging;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Implementation of the <see cref="Spring.Aop.Framework.IAopProxyFactory"/>
/// interface that caches the AOP proxy <see cref="System.Type"/> instance.
/// </summary>
/// <remarks>
/// <p>
/// Caches against a key based on :
/// - the base type
/// - the target type
/// - the interfaces to proxy
/// </p>
/// </remarks>
/// <author>Bruno Baia</author>
/// <author>Erich Eichinger</author>
/// <seealso cref="Spring.Aop.Framework.DynamicProxy.DefaultAopProxyFactory"/>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory"/>
/// <version>$Id: CachedAopProxyFactory.cs,v 1.1 2007/08/02 04:15:21 markpollack Exp $</version>
[Serializable]
public class CachedAopProxyFactory : DefaultAopProxyFactory
{
/// <summary>
/// The shared <see cref="Common.Logging.ILog"/> instance for this class.
/// </summary>
private static readonly ILog logger = LogManager.GetLogger(typeof(CachedAopProxyFactory));
private static Hashtable typeCache = new Hashtable();
/// <summary>
/// Generates the proxy type and caches the <see cref="System.Type"/>
/// instance against the base type and the interfaces to proxy.
/// </summary>
/// <param name="typeBuilder">
/// The <see cref="Spring.Proxy.IProxyTypeBuilder"/> to use
/// </param>
/// <returns>The generated or cached proxy class.</returns>
protected override Type BuildProxyType(IProxyTypeBuilder typeBuilder)
{
ProxyTypeCacheKey cacheKey = new ProxyTypeCacheKey(
typeBuilder.BaseType, typeBuilder.TargetType, typeBuilder.Interfaces);
Type proxyType = null;
lock (typeCache)
{
proxyType = typeCache[cacheKey] as Type;
if (proxyType == null)
{
proxyType = typeBuilder.BuildProxyType();
typeCache[cacheKey] = proxyType;
}
else
{
#region Instrumentation
if (logger.IsInfoEnabled)
{
logger.Info(String.Format(
"AOP proxy type found in cache for '{0}'.", cacheKey));
}
#endregion
}
}
return proxyType;
}
#region ProxyTypeCacheKey inner class implementation
/// <summary>
/// Uniquely identifies a proxytype in the cache
/// </summary>
private sealed class ProxyTypeCacheKey
{
private sealed class HashCodeComparer : IComparer
{
public int Compare(object x, object y)
{
return x.GetHashCode().CompareTo(y.GetHashCode());
}
}
private static IComparer interfaceComparer = new HashCodeComparer();
private Type baseType;
private Type targetType;
private Type[] interfaceTypes;
public ProxyTypeCacheKey(Type baseType, Type targetType, Type[] interfaceTypes)
{
this.baseType = baseType;
this.targetType = targetType;
Array.Sort(interfaceTypes, interfaceComparer); // sort by GetHashcode()? to have a defined order
this.interfaceTypes = interfaceTypes;
}
public override bool Equals(object obj)
{
if (this == obj)
{
return true;
}
ProxyTypeCacheKey proxyTypeCacheKey = obj as ProxyTypeCacheKey;
if (proxyTypeCacheKey == null)
{
return false;
}
if (!Equals(targetType, proxyTypeCacheKey.targetType))
{
return false;
}
if (!Equals(baseType, proxyTypeCacheKey.baseType))
{
return false;
}
for (int i = 0; i < interfaceTypes.Length; i++)
{
if (!Equals(interfaceTypes[i], proxyTypeCacheKey.interfaceTypes[i]))
{
return false;
}
}
return true;
}
public override int GetHashCode()
{
int result = baseType.GetHashCode();
result = 29*result + targetType.GetHashCode();
for (int i = 0; i < interfaceTypes.Length; i++)
{
result = 29 * result + interfaceTypes[i].GetHashCode();
}
return result;
}
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("baseType=" + baseType + "; ");
buffer.Append("targetType=" + targetType + "; ");
buffer.Append("interfaceTypes=[");
foreach (Type intf in interfaceTypes)
{
buffer.Append(intf + ";");
}
buffer.Append("]; ");
return buffer.ToString();
}
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Text;
using System.Collections;
using Common.Logging;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Implementation of the <see cref="Spring.Aop.Framework.IAopProxyFactory"/>
/// interface that caches the AOP proxy <see cref="System.Type"/> instance.
/// </summary>
/// <remarks>
/// <p>
/// Caches against a key based on :
/// - the base type
/// - the target type
/// - the interfaces to proxy
/// </p>
/// </remarks>
/// <author>Bruno Baia</author>
/// <author>Erich Eichinger</author>
/// <seealso cref="Spring.Aop.Framework.DynamicProxy.DefaultAopProxyFactory"/>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory"/>
[Serializable]
public class CachedAopProxyFactory : DefaultAopProxyFactory
{
/// <summary>
/// The shared <see cref="Common.Logging.ILog"/> instance for this class.
/// </summary>
private static readonly ILog logger = LogManager.GetLogger(typeof(CachedAopProxyFactory));
private static Hashtable typeCache = new Hashtable();
/// <summary>
/// Generates the proxy type and caches the <see cref="System.Type"/>
/// instance against the base type and the interfaces to proxy.
/// </summary>
/// <param name="typeBuilder">
/// The <see cref="Spring.Proxy.IProxyTypeBuilder"/> to use
/// </param>
/// <returns>The generated or cached proxy class.</returns>
protected override Type BuildProxyType(IProxyTypeBuilder typeBuilder)
{
ProxyTypeCacheKey cacheKey = new ProxyTypeCacheKey(
typeBuilder.BaseType, typeBuilder.TargetType, typeBuilder.Interfaces);
Type proxyType = null;
lock (typeCache)
{
proxyType = typeCache[cacheKey] as Type;
if (proxyType == null)
{
proxyType = typeBuilder.BuildProxyType();
typeCache[cacheKey] = proxyType;
}
else
{
#region Instrumentation
if (logger.IsInfoEnabled)
{
logger.Info(String.Format(
"AOP proxy type found in cache for '{0}'.", cacheKey));
}
#endregion
}
}
return proxyType;
}
#region ProxyTypeCacheKey inner class implementation
/// <summary>
/// Uniquely identifies a proxytype in the cache
/// </summary>
private sealed class ProxyTypeCacheKey
{
private sealed class HashCodeComparer : IComparer
{
public int Compare(object x, object y)
{
return x.GetHashCode().CompareTo(y.GetHashCode());
}
}
private static IComparer interfaceComparer = new HashCodeComparer();
private Type baseType;
private Type targetType;
private Type[] interfaceTypes;
public ProxyTypeCacheKey(Type baseType, Type targetType, Type[] interfaceTypes)
{
this.baseType = baseType;
this.targetType = targetType;
Array.Sort(interfaceTypes, interfaceComparer); // sort by GetHashcode()? to have a defined order
this.interfaceTypes = interfaceTypes;
}
public override bool Equals(object obj)
{
if (this == obj)
{
return true;
}
ProxyTypeCacheKey proxyTypeCacheKey = obj as ProxyTypeCacheKey;
if (proxyTypeCacheKey == null)
{
return false;
}
if (!Equals(targetType, proxyTypeCacheKey.targetType))
{
return false;
}
if (!Equals(baseType, proxyTypeCacheKey.baseType))
{
return false;
}
for (int i = 0; i < interfaceTypes.Length; i++)
{
if (!Equals(interfaceTypes[i], proxyTypeCacheKey.interfaceTypes[i]))
{
return false;
}
}
return true;
}
public override int GetHashCode()
{
int result = baseType.GetHashCode();
result = 29*result + targetType.GetHashCode();
for (int i = 0; i < interfaceTypes.Length; i++)
{
result = 29 * result + interfaceTypes[i].GetHashCode();
}
return result;
}
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("baseType=" + baseType + "; ");
buffer.Append("targetType=" + targetType + "; ");
buffer.Append("interfaceTypes=[");
foreach (Type intf in interfaceTypes)
{
buffer.Append(intf + ";");
}
buffer.Append("]; ");
return buffer.ToString();
}
}
#endregion
}
}

View File

@@ -1,213 +1,212 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Serialization;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using composition.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
/// <version>$Id: CompositionAopProxyTypeBuilder.cs,v 1.15 2007/12/07 17:58:56 bbaia Exp $</version>
public class CompositionAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "CompositionAopProxy";
private IAdvised advised;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="CompositionAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public CompositionAopProxyTypeBuilder(IAdvised advised)
{
this.advised = advised;
Name = PROXY_TYPE_NAME;
BaseType = typeof(BaseCompositionAopProxy);
TargetType = advised.TargetSource.TargetType.IsInterface ? typeof(object) : advised.TargetSource.TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy type.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface
ImplementInterface(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, false, targetMethods),
intf, TargetType);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor) target)),
intf, TargetType);
}
}
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string) entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo) entry.Value);
}
return proxyType;
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
}
#endregion
#region Protected Methods
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Call, References.BaseCompositionAopProxySerializationConstructor);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements constructors for the proxy class.
/// </summary>
/// <remarks>
/// <p>
/// This implementation calls the base constructor.
/// </p>
/// </remarks>
/// <param name="typeBuilder">
/// The <see cref="System.Type"/> builder to use.
/// </param>
protected override void ImplementConstructors(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(References.BaseCompositionAopProxyConstructor.Attributes,
References.BaseCompositionAopProxyConstructor.CallingConvention,
new Type[] { typeof(IAdvised) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, References.BaseCompositionAopProxyConstructor);
il.Emit(OpCodes.Ret);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a composition-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsCompositionProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Serialization;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using composition.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
public class CompositionAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "CompositionAopProxy";
private IAdvised advised;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="CompositionAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public CompositionAopProxyTypeBuilder(IAdvised advised)
{
this.advised = advised;
Name = PROXY_TYPE_NAME;
BaseType = typeof(BaseCompositionAopProxy);
TargetType = advised.TargetSource.TargetType.IsInterface ? typeof(object) : advised.TargetSource.TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy type.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface
ImplementInterface(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, false, targetMethods),
intf, TargetType);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor) target)),
intf, TargetType);
}
}
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string) entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo) entry.Value);
}
return proxyType;
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
}
#endregion
#region Protected Methods
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Call, References.BaseCompositionAopProxySerializationConstructor);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements constructors for the proxy class.
/// </summary>
/// <remarks>
/// <p>
/// This implementation calls the base constructor.
/// </p>
/// </remarks>
/// <param name="typeBuilder">
/// The <see cref="System.Type"/> builder to use.
/// </param>
protected override void ImplementConstructors(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(References.BaseCompositionAopProxyConstructor.Attributes,
References.BaseCompositionAopProxyConstructor.CallingConvention,
new Type[] { typeof(IAdvised) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, References.BaseCompositionAopProxyConstructor);
il.Emit(OpCodes.Ret);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a composition-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsCompositionProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
}

View File

@@ -1,317 +1,316 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Serialization;
using Spring.Util;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using the decorator pattern.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: DecoratorAopProxyTypeBuilder.cs,v 1.17 2007/12/07 17:58:56 bbaia Exp $</version>
public class DecoratorAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "DecoratorAopProxy";
private IAdvised advised;
/// <summary>
/// AdvisedProxy instance calls should be delegated to.
/// </summary>
protected FieldBuilder advisedProxyField;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="DecoratorAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public DecoratorAopProxyTypeBuilder(IAdvised advised)
{
if (!ReflectionUtils.IsTypeVisible(advised.TargetSource.TargetType, DynamicProxyManager.ASSEMBLY_NAME))
{
throw new AopConfigException(String.Format(
"Cannot create decorator-based IAopProxy for a non visible class [{0}]",
advised.TargetSource.TargetType.FullName));
}
if (advised.TargetSource.TargetType.IsSealed)
{
throw new AopConfigException(String.Format(
"Cannot create decorator-based IAopProxy for a sealed class [{0}]",
advised.TargetSource.TargetType.FullName));
}
this.advised = advised;
Name = PROXY_TYPE_NAME;
TargetType = advised.TargetSource.TargetType.IsInterface ? typeof(object) : advised.TargetSource.TargetType;
BaseType = TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy class.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
// declare fields
DeclareAdvisedProxyInstanceField(typeBuilder);
// implement ISerializable if possible
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
ImplementGetObjectDataMethod(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface (proxy only final methods)
ImplementInterface(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, true, targetMethods),
intf, TargetType, false);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor)target)),
intf, TargetType);
}
}
// inherit from target type
InheritType(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, false, targetMethods),
TargetType);
// implement IAdvised interface
ImplementInterface(typeBuilder,
new IAdvisedProxyMethodBuilder(typeBuilder, this),
typeof(IAdvised), TargetType);
// implement IAopProxy interface
ImplementIAopProxy(typeBuilder);
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo)entry.Value);
}
return proxyType;
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
}
#endregion
#region Protected Methods
/// <summary>
/// Declares field that holds the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance used by the proxy.
/// </summary>
/// <param name="builder">
/// The <see cref="System.Type"/> builder to use for code generation.
/// </param>
protected virtual void DeclareAdvisedProxyInstanceField(TypeBuilder builder)
{
advisedProxyField = builder.DefineField("__advisedProxy", typeof(AdvisedProxy), FieldAttributes.Private);
}
/// <summary>
/// Implements serialization method.
/// </summary>
/// <param name="typeBuilder"></param>
private void ImplementGetObjectDataMethod(TypeBuilder typeBuilder)
{
typeBuilder.AddInterfaceImplementation(typeof(ISerializable));
MethodBuilder mb =
typeBuilder.DefineMethod("GetObjectData",
MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.NewSlot | MethodAttributes.Virtual,
typeof (void),
new Type[] {typeof (SerializationInfo), typeof (StreamingContext)});
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
il.EmitCall(OpCodes.Callvirt, References.AddSerializationValue, null);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, typeof(ISerializable).GetMethod("GetObjectData"));
}
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldtoken, typeof(AdvisedProxy));
il.EmitCall(OpCodes.Call, References.GetTypeFromHandle, null);
il.EmitCall(OpCodes.Callvirt, References.GetSerializationValue, null);
il.Emit(OpCodes.Castclass, typeof(AdvisedProxy));
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements constructors for the proxy class.
/// </summary>
/// <remarks>
/// <p>
/// This implementation creates a new instance
/// of the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/> class.
/// </p>
/// </remarks>
/// <param name="typeBuilder">
/// The <see cref="System.Type"/> builder to use.
/// </param>
protected override void ImplementConstructors(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(References.ObjectConstructor.Attributes,
References.ObjectConstructor.CallingConvention,
new Type[] { typeof(IAdvised) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Newobj, References.AdvisedProxyConstructor);
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements <see cref="Spring.Aop.Framework.IAopProxy"/> interface.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
protected virtual void ImplementIAopProxy(TypeBuilder typeBuilder)
{
Type intf = typeof(IAopProxy);
MethodInfo getProxyMethod = intf.GetMethod("GetProxy", Type.EmptyTypes);
typeBuilder.AddInterfaceImplementation(intf);
MethodBuilder mb = typeBuilder.DefineMethod(typeof(IAdvised).FullName + "." + getProxyMethod.Name,
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
getProxyMethod.CallingConvention, getProxyMethod.ReturnType, Type.EmptyTypes);
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, getProxyMethod);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a decorator-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsDecoratorProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Serialization;
using Spring.Util;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using the decorator pattern.
/// </summary>
/// <author>Bruno Baia</author>
public class DecoratorAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "DecoratorAopProxy";
private IAdvised advised;
/// <summary>
/// AdvisedProxy instance calls should be delegated to.
/// </summary>
protected FieldBuilder advisedProxyField;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="DecoratorAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public DecoratorAopProxyTypeBuilder(IAdvised advised)
{
if (!ReflectionUtils.IsTypeVisible(advised.TargetSource.TargetType, DynamicProxyManager.ASSEMBLY_NAME))
{
throw new AopConfigException(String.Format(
"Cannot create decorator-based IAopProxy for a non visible class [{0}]",
advised.TargetSource.TargetType.FullName));
}
if (advised.TargetSource.TargetType.IsSealed)
{
throw new AopConfigException(String.Format(
"Cannot create decorator-based IAopProxy for a sealed class [{0}]",
advised.TargetSource.TargetType.FullName));
}
this.advised = advised;
Name = PROXY_TYPE_NAME;
TargetType = advised.TargetSource.TargetType.IsInterface ? typeof(object) : advised.TargetSource.TargetType;
BaseType = TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy class.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
// declare fields
DeclareAdvisedProxyInstanceField(typeBuilder);
// implement ISerializable if possible
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
ImplementGetObjectDataMethod(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface (proxy only final methods)
ImplementInterface(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, true, targetMethods),
intf, TargetType, false);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor)target)),
intf, TargetType);
}
}
// inherit from target type
InheritType(typeBuilder,
new TargetAopProxyMethodBuilder(typeBuilder, this, false, targetMethods),
TargetType);
// implement IAdvised interface
ImplementInterface(typeBuilder,
new IAdvisedProxyMethodBuilder(typeBuilder, this),
typeof(IAdvised), TargetType);
// implement IAopProxy interface
ImplementIAopProxy(typeBuilder);
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo)entry.Value);
}
return proxyType;
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
}
#endregion
#region Protected Methods
/// <summary>
/// Declares field that holds the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance used by the proxy.
/// </summary>
/// <param name="builder">
/// The <see cref="System.Type"/> builder to use for code generation.
/// </param>
protected virtual void DeclareAdvisedProxyInstanceField(TypeBuilder builder)
{
advisedProxyField = builder.DefineField("__advisedProxy", typeof(AdvisedProxy), FieldAttributes.Private);
}
/// <summary>
/// Implements serialization method.
/// </summary>
/// <param name="typeBuilder"></param>
private void ImplementGetObjectDataMethod(TypeBuilder typeBuilder)
{
typeBuilder.AddInterfaceImplementation(typeof(ISerializable));
MethodBuilder mb =
typeBuilder.DefineMethod("GetObjectData",
MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.NewSlot | MethodAttributes.Virtual,
typeof (void),
new Type[] {typeof (SerializationInfo), typeof (StreamingContext)});
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
il.EmitCall(OpCodes.Callvirt, References.AddSerializationValue, null);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, typeof(ISerializable).GetMethod("GetObjectData"));
}
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldtoken, typeof(AdvisedProxy));
il.EmitCall(OpCodes.Call, References.GetTypeFromHandle, null);
il.EmitCall(OpCodes.Callvirt, References.GetSerializationValue, null);
il.Emit(OpCodes.Castclass, typeof(AdvisedProxy));
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements constructors for the proxy class.
/// </summary>
/// <remarks>
/// <p>
/// This implementation creates a new instance
/// of the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/> class.
/// </p>
/// </remarks>
/// <param name="typeBuilder">
/// The <see cref="System.Type"/> builder to use.
/// </param>
protected override void ImplementConstructors(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(References.ObjectConstructor.Attributes,
References.ObjectConstructor.CallingConvention,
new Type[] { typeof(IAdvised) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Newobj, References.AdvisedProxyConstructor);
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Implements <see cref="Spring.Aop.Framework.IAopProxy"/> interface.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
protected virtual void ImplementIAopProxy(TypeBuilder typeBuilder)
{
Type intf = typeof(IAopProxy);
MethodInfo getProxyMethod = intf.GetMethod("GetProxy", Type.EmptyTypes);
typeBuilder.AddInterfaceImplementation(intf);
MethodBuilder mb = typeBuilder.DefineMethod(typeof(IAdvised).FullName + "." + getProxyMethod.Name,
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
getProxyMethod.CallingConvention, getProxyMethod.ReturnType, Type.EmptyTypes);
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, getProxyMethod);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a decorator-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsDecoratorProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
}

View File

@@ -1,110 +1,109 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Proxy;
using Spring.Aop.Target;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Default implementation of the
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> interface,
/// either creating a decorator-based dynamic proxy or
/// a composition-based dynamic proxy.
/// </summary>
/// <remarks>
/// <p>
/// Creates a decorator-base proxy if one the following is true :
/// - the "ProxyTargetType" property is set
/// - no interfaces have been specified
/// </p>
/// <p>
/// In general, specify "ProxyTargetType" to enforce a decorator-based proxy,
/// or specify one or more interfaces to use a composition-based proxy.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory"/>
/// <version>$Id: DefaultAopProxyFactory.cs,v 1.2 2007/08/02 16:28:29 bbaia Exp $</version>
[Serializable]
public class DefaultAopProxyFactory : IAopProxyFactory
{
/// <summary>
/// Creates an <see cref="Spring.Aop.Framework.IAopProxy"/> for the
/// supplied <paramref name="advisedSupport"/> configuration.
/// </summary>
/// <param name="advisedSupport">The AOP configuration.</param>
/// <returns>An <see cref="Spring.Aop.Framework.IAopProxy"/>.</returns>
/// <exception cref="AopConfigException">
/// If the supplied <paramref name="advisedSupport"/> configuration is
/// invalid.
/// </exception>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory.CreateAopProxy"/>
public virtual IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
{
if (advisedSupport == null)
{
throw new AopConfigException("Cannot create IAopProxy with null ProxyConfig");
}
if (advisedSupport.Advisors.Length == 0 && advisedSupport.TargetSource == EmptyTargetSource.Empty)
{
throw new AopConfigException("Cannot create IAopProxy with no advisors and no target source");
}
if (advisedSupport.ProxyType == null)
{
IProxyTypeBuilder typeBuilder;
if ((advisedSupport.ProxyTargetType) ||
(advisedSupport.Interfaces.Length == 0))
{
typeBuilder = new DecoratorAopProxyTypeBuilder(advisedSupport);
}
else
{
typeBuilder = new CompositionAopProxyTypeBuilder(advisedSupport);
}
advisedSupport.ProxyType = BuildProxyType(typeBuilder);
advisedSupport.ProxyConstructor = advisedSupport.ProxyType.GetConstructor(new Type[] { typeof(IAdvised) });
}
return (IAopProxy)advisedSupport.ProxyConstructor.Invoke(new object[] { advisedSupport });
}
/// <summary>
/// Generates the proxy type.
/// </summary>
/// <param name="typeBuilder">
/// The <see cref="Spring.Proxy.IProxyTypeBuilder"/> to use
/// </param>
/// <returns>The generated proxy class.</returns>
protected virtual Type BuildProxyType(IProxyTypeBuilder typeBuilder)
{
return typeBuilder.BuildProxyType();
}
}
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Proxy;
using Spring.Aop.Target;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Default implementation of the
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> interface,
/// either creating a decorator-based dynamic proxy or
/// a composition-based dynamic proxy.
/// </summary>
/// <remarks>
/// <p>
/// Creates a decorator-base proxy if one the following is true :
/// - the "ProxyTargetType" property is set
/// - no interfaces have been specified
/// </p>
/// <p>
/// In general, specify "ProxyTargetType" to enforce a decorator-based proxy,
/// or specify one or more interfaces to use a composition-based proxy.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory"/>
[Serializable]
public class DefaultAopProxyFactory : IAopProxyFactory
{
/// <summary>
/// Creates an <see cref="Spring.Aop.Framework.IAopProxy"/> for the
/// supplied <paramref name="advisedSupport"/> configuration.
/// </summary>
/// <param name="advisedSupport">The AOP configuration.</param>
/// <returns>An <see cref="Spring.Aop.Framework.IAopProxy"/>.</returns>
/// <exception cref="AopConfigException">
/// If the supplied <paramref name="advisedSupport"/> configuration is
/// invalid.
/// </exception>
/// <seealso cref="Spring.Aop.Framework.IAopProxyFactory.CreateAopProxy"/>
public virtual IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
{
if (advisedSupport == null)
{
throw new AopConfigException("Cannot create IAopProxy with null ProxyConfig");
}
if (advisedSupport.Advisors.Length == 0 && advisedSupport.TargetSource == EmptyTargetSource.Empty)
{
throw new AopConfigException("Cannot create IAopProxy with no advisors and no target source");
}
if (advisedSupport.ProxyType == null)
{
IProxyTypeBuilder typeBuilder;
if ((advisedSupport.ProxyTargetType) ||
(advisedSupport.Interfaces.Length == 0))
{
typeBuilder = new DecoratorAopProxyTypeBuilder(advisedSupport);
}
else
{
typeBuilder = new CompositionAopProxyTypeBuilder(advisedSupport);
}
advisedSupport.ProxyType = BuildProxyType(typeBuilder);
advisedSupport.ProxyConstructor = advisedSupport.ProxyType.GetConstructor(new Type[] { typeof(IAdvised) });
}
return (IAopProxy)advisedSupport.ProxyConstructor.Invoke(new object[] { advisedSupport });
}
/// <summary>
/// Generates the proxy type.
/// </summary>
/// <param name="typeBuilder">
/// The <see cref="Spring.Proxy.IProxyTypeBuilder"/> to use
/// </param>
/// <returns>The generated proxy class.</returns>
protected virtual Type BuildProxyType(IProxyTypeBuilder typeBuilder)
{
return typeBuilder.BuildProxyType();
}
}
}

View File

@@ -1,83 +1,82 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation that delegates
/// method calls to an <see cref="Spring.Aop.Framework.IAdvised"/> instance.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: IAdvisedProxyMethodBuilder.cs,v 1.3 2006/11/12 01:37:47 bbaia Exp $</version>
public class IAdvisedProxyMethodBuilder : TargetProxyMethodBuilder
{
#region Fields
/// <summary>
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </summary>
private IAopProxyTypeGenerator _aopProxyGenerator;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
public IAdvisedProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator)
: base(typeBuilder, aopProxyGenerator, true)
{
this._aopProxyGenerator = aopProxyGenerator;
}
#endregion
#region Protected Methods
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTarget(ILGenerator il)
{
_aopProxyGenerator.PushAdvisedProxy(il);
}
#endregion
}
}
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation that delegates
/// method calls to an <see cref="Spring.Aop.Framework.IAdvised"/> instance.
/// </summary>
/// <author>Bruno Baia</author>
public class IAdvisedProxyMethodBuilder : TargetProxyMethodBuilder
{
#region Fields
/// <summary>
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </summary>
private IAopProxyTypeGenerator _aopProxyGenerator;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
public IAdvisedProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator)
: base(typeBuilder, aopProxyGenerator, true)
{
this._aopProxyGenerator = aopProxyGenerator;
}
#endregion
#region Protected Methods
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTarget(ILGenerator il)
{
_aopProxyGenerator.PushAdvisedProxy(il);
}
#endregion
}
}

View File

@@ -1,48 +1,47 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection.Emit;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Describes the operations that generates IL instructions
/// used to build the Aop proxy type.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: IAopProxyTypeGenerator.cs,v 1.2 2006/11/05 20:36:59 bbaia Exp $</version>
public interface IAopProxyTypeGenerator : IProxyTypeGenerator
{
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
void PushAdvisedProxy(ILGenerator il);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection.Emit;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Describes the operations that generates IL instructions
/// used to build the Aop proxy type.
/// </summary>
/// <author>Bruno Baia</author>
public interface IAopProxyTypeGenerator : IProxyTypeGenerator
{
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
void PushAdvisedProxy(ILGenerator il);
}
}

View File

@@ -1,397 +1,396 @@
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Core;
using Spring.Proxy;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using inheritance.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: InheritanceAopProxyTypeBuilder.cs,v 1.2 2008/03/03 09:28:50 bbaia Exp $</version>
public class InheritanceAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "InheritanceAopProxy";
private IAdvised advised;
private bool proxyDeclaredMembersOnly = true;
/// <summary>
/// AdvisedProxy instance calls should be delegated to.
/// </summary>
protected FieldBuilder advisedProxyField;
#endregion
#region Properties
/// <summary>
/// Gets or sets a value indicating whether inherited members should be proxied.
/// </summary>
/// <value>
/// <see langword="true"/> if inherited members should be proxied;
/// otherwise, <see langword="false"/>.
/// </value>
public bool ProxyDeclaredMembersOnly
{
get { return proxyDeclaredMembersOnly; }
set { proxyDeclaredMembersOnly = value; }
}
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="CompositionAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public InheritanceAopProxyTypeBuilder(IAdvised advised)
{
if (!ReflectionUtils.IsTypeVisible(advised.TargetSource.TargetType, DynamicProxyManager.ASSEMBLY_NAME))
{
throw new AopConfigException(String.Format(
"Cannot create inheritance-based IAopProxy for a non visible class [{0}]",
advised.TargetSource.TargetType.FullName));
}
if (advised.TargetSource.TargetType.IsSealed)
{
throw new AopConfigException(String.Format(
"Cannot create inheritance-based IAopProxy for a sealed class [{0}]",
advised.TargetSource.TargetType.FullName));
}
this.advised = advised;
Name = PROXY_TYPE_NAME;
TargetType = advised.TargetSource.TargetType;
BaseType = TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy class.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
IDictionary proxyMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
// declare fields
DeclareAdvisedProxyInstanceField(typeBuilder);
// implement ISerializable if possible
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
ImplementGetObjectDataMethod(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface (proxy only final methods)
ImplementInterface(typeBuilder,
new BaseAopProxyMethodBuilder(typeBuilder, this, targetMethods, proxyMethods),
intf, TargetType, false);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor)target)),
intf, TargetType);
}
}
// inherit from target type
InheritType(typeBuilder,
new BaseAopProxyMethodBuilder(typeBuilder, this, targetMethods, proxyMethods),
TargetType, ProxyDeclaredMembersOnly);
// implement IAdvised interface
ImplementInterface(typeBuilder,
new IAdvisedProxyMethodBuilder(typeBuilder, this),
typeof(IAdvised), TargetType);
// implement IAopProxy interface
ImplementIAopProxy(typeBuilder);
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo)entry.Value);
}
// set proxy method references
foreach (DictionaryEntry entry in proxyMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, FindProxyMethod(proxyType, (MethodInfo)entry.Value));
}
return proxyType;
}
private MethodInfo FindProxyMethod(Type targetType, MethodInfo method)
{
ComposedCriteria searchCriteria = new ComposedCriteria();
searchCriteria.Add(new MethodNameMatchCriteria("proxy_" + method.Name));
searchCriteria.Add(new MethodParametersCountCriteria(method.GetParameters().Length));
#if NET_2_0
searchCriteria.Add(new MethodGenericArgumentsCountCriteria(
method.GetGenericArguments().Length));
#endif
searchCriteria.Add(new MethodParametersCriteria(ReflectionUtils.GetParameterTypes(method)));
MemberInfo[] matchingMethods = targetType.FindMembers(
MemberTypes.Method,
BindingFlags.Instance | BindingFlags.Public,
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
searchCriteria);
if (matchingMethods != null && matchingMethods.Length == 1)
{
return matchingMethods[0] as MethodInfo;
}
else
{
throw new AmbiguousMatchException();
}
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushTarget(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
}
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
}
#endregion
#region Protected Methods
/// <summary>
/// Declares field that holds the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance used by the proxy.
/// </summary>
/// <param name="builder">
/// The <see cref="System.Type"/> builder to use for code generation.
/// </param>
protected virtual void DeclareAdvisedProxyInstanceField(TypeBuilder builder)
{
advisedProxyField = builder.DefineField("__advisedProxy", typeof(AdvisedProxy), FieldAttributes.Private);
}
/// <summary>
/// Implements serialization method.
/// </summary>
/// <param name="typeBuilder"></param>
private void ImplementGetObjectDataMethod(TypeBuilder typeBuilder)
{
typeBuilder.AddInterfaceImplementation(typeof(ISerializable));
MethodBuilder mb =
typeBuilder.DefineMethod("GetObjectData",
MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.NewSlot | MethodAttributes.Virtual,
typeof(void),
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
il.EmitCall(OpCodes.Callvirt, References.AddSerializationValue, null);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, typeof(ISerializable).GetMethod("GetObjectData"));
}
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldtoken, typeof(AdvisedProxy));
il.EmitCall(OpCodes.Call, References.GetTypeFromHandle, null);
il.EmitCall(OpCodes.Callvirt, References.GetSerializationValue, null);
il.Emit(OpCodes.Castclass, typeof(AdvisedProxy));
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Defines the types of the parameters for the specified constructor.
/// </summary>
/// <param name="constructor">The constructor to use.</param>
/// <returns>The types for constructor's parameters.</returns>
protected override Type[] DefineConstructorParameters(ConstructorInfo constructor)
{
Type[] currentParams = ReflectionUtils.GetParameterTypes(constructor.GetParameters());
Type[] newParams = new Type[currentParams.Length + 1];
newParams[currentParams.Length] = typeof(IAdvised);
currentParams.CopyTo(newParams, 0);
return newParams;
}
/// <summary>
/// Generates the proxy constructor.
/// </summary>
/// <remarks>
/// <p>
/// This implementation creates instance of the AdvisedProxy object.
/// </p>
/// </remarks>
/// <param name="builder">The constructor builder to use.</param>
/// <param name="il">The IL generator to use.</param>
/// <param name="constructor">The constructor to delegate the creation to.</param>
protected override void GenerateConstructor(
ConstructorBuilder builder, ILGenerator il, ConstructorInfo constructor)
{
int paramCount = constructor.GetParameters().Length;
il.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < paramCount; i++)
{
il.Emit(OpCodes.Ldarg_S, i + 1);
}
il.Emit(OpCodes.Call, constructor);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_S, paramCount + 1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Newobj, References.AdvisedProxyConstructor);
il.Emit(OpCodes.Stfld, advisedProxyField);
}
/// <summary>
/// Implements <see cref="Spring.Aop.Framework.IAopProxy"/> interface.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
protected virtual void ImplementIAopProxy(TypeBuilder typeBuilder)
{
Type intf = typeof(IAopProxy);
MethodInfo getProxyMethod = intf.GetMethod("GetProxy", Type.EmptyTypes);
typeBuilder.AddInterfaceImplementation(intf);
MethodBuilder mb = typeBuilder.DefineMethod(typeof(IAdvised).FullName + "." + getProxyMethod.Name,
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
getProxyMethod.CallingConvention, getProxyMethod.ReturnType, Type.EmptyTypes);
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, getProxyMethod);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a inheritance-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsInheritanceProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Runtime.Serialization;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Core;
using Spring.Proxy;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Builds an AOP proxy type using inheritance.
/// </summary>
/// <author>Bruno Baia</author>
public class InheritanceAopProxyTypeBuilder : AbstractAopProxyTypeBuilder
{
#region Fields
private const string PROXY_TYPE_NAME = "InheritanceAopProxy";
private IAdvised advised;
private bool proxyDeclaredMembersOnly = true;
/// <summary>
/// AdvisedProxy instance calls should be delegated to.
/// </summary>
protected FieldBuilder advisedProxyField;
#endregion
#region Properties
/// <summary>
/// Gets or sets a value indicating whether inherited members should be proxied.
/// </summary>
/// <value>
/// <see langword="true"/> if inherited members should be proxied;
/// otherwise, <see langword="false"/>.
/// </value>
public bool ProxyDeclaredMembersOnly
{
get { return proxyDeclaredMembersOnly; }
set { proxyDeclaredMembersOnly = value; }
}
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="CompositionAopProxyTypeBuilder"/> class.
/// </summary>
/// <param name="advised">The proxy configuration.</param>
public InheritanceAopProxyTypeBuilder(IAdvised advised)
{
if (!ReflectionUtils.IsTypeVisible(advised.TargetSource.TargetType, DynamicProxyManager.ASSEMBLY_NAME))
{
throw new AopConfigException(String.Format(
"Cannot create inheritance-based IAopProxy for a non visible class [{0}]",
advised.TargetSource.TargetType.FullName));
}
if (advised.TargetSource.TargetType.IsSealed)
{
throw new AopConfigException(String.Format(
"Cannot create inheritance-based IAopProxy for a sealed class [{0}]",
advised.TargetSource.TargetType.FullName));
}
this.advised = advised;
Name = PROXY_TYPE_NAME;
TargetType = advised.TargetSource.TargetType;
BaseType = TargetType;
Interfaces = GetProxiableInterfaces(advised.Interfaces);
ProxyTargetAttributes = advised.ProxyTargetAttributes;
}
#endregion
#region IProxyTypeBuilder Members
/// <summary>
/// Creates the proxy type.
/// </summary>
/// <returns>The generated proxy class.</returns>
public override Type BuildProxyType()
{
IDictionary targetMethods = new Hashtable();
IDictionary proxyMethods = new Hashtable();
TypeBuilder typeBuilder = CreateTypeBuilder(Name, BaseType);
// apply custom attributes to the proxy type.
ApplyTypeAttributes(typeBuilder, TargetType);
// declare fields
DeclareAdvisedProxyInstanceField(typeBuilder);
// implement ISerializable if possible
if (advised.IsSerializable)
{
typeBuilder.SetCustomAttribute(
ReflectionUtils.CreateCustomAttribute(typeof(SerializableAttribute)));
ImplementSerializationConstructor(typeBuilder);
ImplementGetObjectDataMethod(typeBuilder);
}
// create constructors
ImplementConstructors(typeBuilder);
// implement interfaces
IDictionary interfaceMap = advised.InterfaceMap;
foreach (Type intf in Interfaces)
{
object target = interfaceMap[intf];
if (target == null)
{
// implement interface (proxy only final methods)
ImplementInterface(typeBuilder,
new BaseAopProxyMethodBuilder(typeBuilder, this, targetMethods, proxyMethods),
intf, TargetType, false);
}
else if (target is IIntroductionAdvisor)
{
// implement introduction
ImplementInterface(typeBuilder,
new IntroductionProxyMethodBuilder(typeBuilder, this, targetMethods, advised.IndexOf((IIntroductionAdvisor)target)),
intf, TargetType);
}
}
// inherit from target type
InheritType(typeBuilder,
new BaseAopProxyMethodBuilder(typeBuilder, this, targetMethods, proxyMethods),
TargetType, ProxyDeclaredMembersOnly);
// implement IAdvised interface
ImplementInterface(typeBuilder,
new IAdvisedProxyMethodBuilder(typeBuilder, this),
typeof(IAdvised), TargetType);
// implement IAopProxy interface
ImplementIAopProxy(typeBuilder);
Type proxyType;
proxyType = typeBuilder.CreateType();
// set target method references
foreach (DictionaryEntry entry in targetMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, (MethodInfo)entry.Value);
}
// set proxy method references
foreach (DictionaryEntry entry in proxyMethods)
{
FieldInfo field = proxyType.GetField((string)entry.Key, BindingFlags.NonPublic | BindingFlags.Static);
field.SetValue(proxyType, FindProxyMethod(proxyType, (MethodInfo)entry.Value));
}
return proxyType;
}
private MethodInfo FindProxyMethod(Type targetType, MethodInfo method)
{
ComposedCriteria searchCriteria = new ComposedCriteria();
searchCriteria.Add(new MethodNameMatchCriteria("proxy_" + method.Name));
searchCriteria.Add(new MethodParametersCountCriteria(method.GetParameters().Length));
#if NET_2_0
searchCriteria.Add(new MethodGenericArgumentsCountCriteria(
method.GetGenericArguments().Length));
#endif
searchCriteria.Add(new MethodParametersCriteria(ReflectionUtils.GetParameterTypes(method)));
MemberInfo[] matchingMethods = targetType.FindMembers(
MemberTypes.Method,
BindingFlags.Instance | BindingFlags.Public,
new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
searchCriteria);
if (matchingMethods != null && matchingMethods.Length == 1)
{
return matchingMethods[0] as MethodInfo;
}
else
{
throw new AmbiguousMatchException();
}
}
#endregion
#region IAopProxyTypeGenerator Members
/// <summary>
/// Generates the IL instructions that pushes
/// the target instance on which calls should be delegated to.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushTarget(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
}
/// <summary>
/// Generates the IL instructions that pushes
/// the current <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
public override void PushAdvisedProxy(ILGenerator il)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
}
#endregion
#region Protected Methods
/// <summary>
/// Declares field that holds the <see cref="Spring.Aop.Framework.DynamicProxy.AdvisedProxy"/>
/// instance used by the proxy.
/// </summary>
/// <param name="builder">
/// The <see cref="System.Type"/> builder to use for code generation.
/// </param>
protected virtual void DeclareAdvisedProxyInstanceField(TypeBuilder builder)
{
advisedProxyField = builder.DefineField("__advisedProxy", typeof(AdvisedProxy), FieldAttributes.Private);
}
/// <summary>
/// Implements serialization method.
/// </summary>
/// <param name="typeBuilder"></param>
private void ImplementGetObjectDataMethod(TypeBuilder typeBuilder)
{
typeBuilder.AddInterfaceImplementation(typeof(ISerializable));
MethodBuilder mb =
typeBuilder.DefineMethod("GetObjectData",
MethodAttributes.Public | MethodAttributes.HideBySig |
MethodAttributes.NewSlot | MethodAttributes.Virtual,
typeof(void),
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, advisedProxyField);
il.EmitCall(OpCodes.Callvirt, References.AddSerializationValue, null);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, typeof(ISerializable).GetMethod("GetObjectData"));
}
/// <summary>
/// Implements serialization constructor.
/// </summary>
/// <param name="typeBuilder">Type builder to use.</param>
private void ImplementSerializationConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder cb =
typeBuilder.DefineConstructor(MethodAttributes.Family,
CallingConventions.Standard,
new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldstr, "advisedProxy");
il.Emit(OpCodes.Ldtoken, typeof(AdvisedProxy));
il.EmitCall(OpCodes.Call, References.GetTypeFromHandle, null);
il.EmitCall(OpCodes.Callvirt, References.GetSerializationValue, null);
il.Emit(OpCodes.Castclass, typeof(AdvisedProxy));
il.Emit(OpCodes.Stfld, advisedProxyField);
il.Emit(OpCodes.Ret);
}
/// <summary>
/// Defines the types of the parameters for the specified constructor.
/// </summary>
/// <param name="constructor">The constructor to use.</param>
/// <returns>The types for constructor's parameters.</returns>
protected override Type[] DefineConstructorParameters(ConstructorInfo constructor)
{
Type[] currentParams = ReflectionUtils.GetParameterTypes(constructor.GetParameters());
Type[] newParams = new Type[currentParams.Length + 1];
newParams[currentParams.Length] = typeof(IAdvised);
currentParams.CopyTo(newParams, 0);
return newParams;
}
/// <summary>
/// Generates the proxy constructor.
/// </summary>
/// <remarks>
/// <p>
/// This implementation creates instance of the AdvisedProxy object.
/// </p>
/// </remarks>
/// <param name="builder">The constructor builder to use.</param>
/// <param name="il">The IL generator to use.</param>
/// <param name="constructor">The constructor to delegate the creation to.</param>
protected override void GenerateConstructor(
ConstructorBuilder builder, ILGenerator il, ConstructorInfo constructor)
{
int paramCount = constructor.GetParameters().Length;
il.Emit(OpCodes.Ldarg_0);
for (int i = 0; i < paramCount; i++)
{
il.Emit(OpCodes.Ldarg_S, i + 1);
}
il.Emit(OpCodes.Call, constructor);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_S, paramCount + 1);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Newobj, References.AdvisedProxyConstructor);
il.Emit(OpCodes.Stfld, advisedProxyField);
}
/// <summary>
/// Implements <see cref="Spring.Aop.Framework.IAopProxy"/> interface.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
protected virtual void ImplementIAopProxy(TypeBuilder typeBuilder)
{
Type intf = typeof(IAopProxy);
MethodInfo getProxyMethod = intf.GetMethod("GetProxy", Type.EmptyTypes);
typeBuilder.AddInterfaceImplementation(intf);
MethodBuilder mb = typeBuilder.DefineMethod(typeof(IAdvised).FullName + "." + getProxyMethod.Name,
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final,
getProxyMethod.CallingConvention, getProxyMethod.ReturnType, Type.EmptyTypes);
ILGenerator il = mb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
typeBuilder.DefineMethodOverride(mb, getProxyMethod);
}
#endregion
#region Public Methods
/// <summary>
/// Determines if the specified <paramref name="type"/>
/// is one of those generated by this builder.
/// </summary>
/// <param name="type">The type to check.</param>
/// <returns>
/// <see langword="true"/> if the type is a inheritance-based proxy;
/// otherwise <see langword="false"/>.
/// </returns>
public static bool IsInheritanceProxy(Type type)
{
return type.FullName.StartsWith(PROXY_TYPE_NAME);
}
#endregion
}
}

View File

@@ -1,117 +1,116 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to introduction object.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
/// <version>$Id: IntroductionProxyMethodBuilder.cs,v 1.5 2006/11/05 20:36:59 bbaia Exp $</version>
public class IntroductionProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Fields
/// <summary>
/// The index of the introduction to delegate call to.
/// </summary>
protected int index;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="targetMethods">
///
/// </param>
/// <param name="index">index of the introduction to delegate call to</param>
public IntroductionProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
IDictionary targetMethods, int index)
: base(typeBuilder, aopProxyGenerator, true, targetMethods)
{
this.index = index;
}
#endregion
#region Protected Methods
/// <summary>
/// Generates the IL instructions that pushes
/// the introduction type on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTargetType(ILGenerator il)
{
PushTarget(il);
il.EmitCall(OpCodes.Call, References.GetTypeMethod, null);
}
/// <summary>
/// Generates the IL instructions that pushes
/// the introduction instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTarget(ILGenerator il)
{
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.IntroductionsField);
il.Emit(OpCodes.Ldc_I4, index);
il.Emit(OpCodes.Ldelem_Ref);
}
/// <summary>
/// Calls proxied method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
CallDirectTargetMethod(il, interfaceMethod);
}
#endregion
}
}
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to introduction object.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
public class IntroductionProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Fields
/// <summary>
/// The index of the introduction to delegate call to.
/// </summary>
protected int index;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="targetMethods">
///
/// </param>
/// <param name="index">index of the introduction to delegate call to</param>
public IntroductionProxyMethodBuilder(
TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
IDictionary targetMethods, int index)
: base(typeBuilder, aopProxyGenerator, true, targetMethods)
{
this.index = index;
}
#endregion
#region Protected Methods
/// <summary>
/// Generates the IL instructions that pushes
/// the introduction type on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTargetType(ILGenerator il)
{
PushTarget(il);
il.EmitCall(OpCodes.Call, References.GetTypeMethod, null);
}
/// <summary>
/// Generates the IL instructions that pushes
/// the introduction instance on stack.
/// </summary>
/// <param name="il">The IL generator to use.</param>
protected override void PushTarget(ILGenerator il)
{
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.IntroductionsField);
il.Emit(OpCodes.Ldc_I4, index);
il.Emit(OpCodes.Ldelem_Ref);
}
/// <summary>
/// Calls proxied method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
CallDirectTargetMethod(il, interfaceMethod);
}
#endregion
}
}

View File

@@ -1,152 +1,151 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to target object.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
/// <version>$Id: TargetAopProxyMethodBuilder.cs,v 1.3 2008/01/29 18:24:50 markpollack Exp $</version>
public class TargetAopProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Fields
/// <summary>
/// The local variable to store
/// the <see cref="Spring.Aop.Framework.ITargetSourceWrapper"/> instance.
/// </summary>
protected LocalBuilder targetSource;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="explicitImplementation">
/// <see langword="true"/> if the interface is to be
/// implemented explicitly; otherwise <see langword="false"/>.
/// </param>
/// <param name="targetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s.
/// </param>
public TargetAopProxyMethodBuilder(TypeBuilder typeBuilder,
IAopProxyTypeGenerator aopProxyGenerator, bool explicitImplementation, IDictionary targetMethods)
: base(typeBuilder, aopProxyGenerator, explicitImplementation, targetMethods)
{
}
#endregion
#region Protected Methods
/// <summary>
/// Creates local variable declarations.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
protected override void DeclareLocals(ILGenerator il, MethodInfo method)
{
base.DeclareLocals(il, method);
targetSource = il.DeclareLocal(typeof(ITargetSourceWrapper));
#if DEBUG
targetSource.SetLocalSymInfo("targetSource");
#endif
}
/// <summary>
/// Generates method logic.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void GenerateMethodLogic(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
Label jmpEndFinally = il.DefineLabel();
// save target source so we can call Dispose later
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.TargetSourceWrapperField);
il.Emit(OpCodes.Stloc, targetSource);
// open try/finally block
il.BeginExceptionBlock();
base.GenerateMethodLogic(il, method, interfaceMethod);
// open finally block
il.BeginFinallyBlock();
// call Dispose on target source
il.Emit(OpCodes.Ldloc, targetSource);
il.Emit(OpCodes.Brfalse, jmpEndFinally);
il.Emit(OpCodes.Ldloc, targetSource);
il.EmitCall(OpCodes.Callvirt, References.DisposeMethod, null);
il.MarkLabel(jmpEndFinally);
// close try/finally block
il.EndExceptionBlock();
}
/// <summary>
/// Calls proxied method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
if (interfaceMethod != null)
CallDirectTargetMethod(il, interfaceMethod);
else
CallDirectTargetMethod(il, method);
}
#endregion
}
}
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// <see cref="Spring.Proxy.IProxyMethodBuilder"/> implementation
/// that delegates method calls to target object.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Bruno Baia</author>
public class TargetAopProxyMethodBuilder : AbstractAopProxyMethodBuilder
{
#region Fields
/// <summary>
/// The local variable to store
/// the <see cref="Spring.Aop.Framework.ITargetSourceWrapper"/> instance.
/// </summary>
protected LocalBuilder targetSource;
#endregion
#region Constructor(s) / Destructor
/// <summary>
/// Creates a new instance of the method builder.
/// </summary>
/// <param name="typeBuilder">The type builder to use.</param>
/// <param name="aopProxyGenerator">
/// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
/// </param>
/// <param name="explicitImplementation">
/// <see langword="true"/> if the interface is to be
/// implemented explicitly; otherwise <see langword="false"/>.
/// </param>
/// <param name="targetMethods">
/// The dictionary to cache the list of target
/// <see cref="System.Reflection.MethodInfo"/>s.
/// </param>
public TargetAopProxyMethodBuilder(TypeBuilder typeBuilder,
IAopProxyTypeGenerator aopProxyGenerator, bool explicitImplementation, IDictionary targetMethods)
: base(typeBuilder, aopProxyGenerator, explicitImplementation, targetMethods)
{
}
#endregion
#region Protected Methods
/// <summary>
/// Creates local variable declarations.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
protected override void DeclareLocals(ILGenerator il, MethodInfo method)
{
base.DeclareLocals(il, method);
targetSource = il.DeclareLocal(typeof(ITargetSourceWrapper));
#if DEBUG
targetSource.SetLocalSymInfo("targetSource");
#endif
}
/// <summary>
/// Generates method logic.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void GenerateMethodLogic(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
Label jmpEndFinally = il.DefineLabel();
// save target source so we can call Dispose later
PushAdvisedProxy(il);
il.Emit(OpCodes.Ldfld, References.TargetSourceWrapperField);
il.Emit(OpCodes.Stloc, targetSource);
// open try/finally block
il.BeginExceptionBlock();
base.GenerateMethodLogic(il, method, interfaceMethod);
// open finally block
il.BeginFinallyBlock();
// call Dispose on target source
il.Emit(OpCodes.Ldloc, targetSource);
il.Emit(OpCodes.Brfalse, jmpEndFinally);
il.Emit(OpCodes.Ldloc, targetSource);
il.EmitCall(OpCodes.Callvirt, References.DisposeMethod, null);
il.MarkLabel(jmpEndFinally);
// close try/finally block
il.EndExceptionBlock();
}
/// <summary>
/// Calls proxied method directly.
/// </summary>
/// <param name="il">The IL generator to use.</param>
/// <param name="method">The method to proxy.</param>
/// <param name="interfaceMethod">
/// The interface definition of the method, if applicable.
/// </param>
protected override void CallDirectProxiedMethod(
ILGenerator il, MethodInfo method, MethodInfo interfaceMethod)
{
if (interfaceMethod != null)
CallDirectTargetMethod(il, interfaceMethod);
else
CallDirectTargetMethod(il, method);
}
#endregion
}
}

View File

@@ -1,98 +1,97 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <remarks>
/// <p>
/// This implementation will release the target object when said object
/// is disposed.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: DynamicTargetSourceWrapper.cs,v 1.4 2007/03/16 04:01:17 aseovic Exp $</version>
[Serializable]
public sealed class DynamicTargetSourceWrapper : ITargetSourceWrapper
{
private ITargetSource targetSource;
private object target;
/// <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>
/// 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;
}
/// <summary>
/// Releases the dynamic target when this object is disposed.
/// </summary>
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
private void Dispose(bool disposing)
{
if (disposing && this.target != null)
{
this.targetSource.ReleaseTarget(this.target);
this.target = null;
}
}
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <remarks>
/// <p>
/// This implementation will release the target object when said object
/// is disposed.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
[Serializable]
public sealed class DynamicTargetSourceWrapper : ITargetSourceWrapper
{
private ITargetSource targetSource;
private object target;
/// <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>
/// 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;
}
/// <summary>
/// Releases the dynamic target when this object is disposed.
/// </summary>
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
private void Dispose(bool disposing)
{
if (disposing && this.target != null)
{
this.targetSource.ReleaseTarget(this.target);
this.target = null;
}
}
}
}

View File

@@ -1,104 +1,103 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/> implementation
/// that caches advisor chains on a per-advised-method basis.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: HashtableCachingAdvisorChainFactory.cs,v 1.9 2007/03/16 04:01:18 aseovic Exp $</version>
[Serializable]
public sealed class HashtableCachingAdvisorChainFactory : IAdvisorChainFactory
{
private IDictionary methodCache = new Hashtable();
/// <summary>
/// Gets the list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </summary>
/// <param name="advised">The proxy configuration object.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method for which the interceptors are to be evaluated.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// The list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </returns>
public IList GetInterceptors(IAdvised advised, object proxy, MethodInfo method, Type targetType)
{
IList cached = (IList) this.methodCache[method];
if (cached == null)
{
// recalculate...
cached = AdvisorChainFactoryUtils.CalculateInterceptors(advised, proxy, method, targetType);
this.methodCache[method] = cached;
}
return cached;
}
/// <summary>
/// Invoked when the first proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void Activated(AdvisedSupport source)
{
}
/// <summary>
/// Invoked when advice is changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void AdviceChanged(AdvisedSupport source)
{
methodCache.Clear();
}
/// <summary>
/// Invoked when interfaces are changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void InterfacesChanged(AdvisedSupport source)
{
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/> implementation
/// that caches advisor chains on a per-advised-method basis.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public sealed class HashtableCachingAdvisorChainFactory : IAdvisorChainFactory
{
private IDictionary methodCache = new Hashtable();
/// <summary>
/// Gets the list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </summary>
/// <param name="advised">The proxy configuration object.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method for which the interceptors are to be evaluated.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// The list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </returns>
public IList GetInterceptors(IAdvised advised, object proxy, MethodInfo method, Type targetType)
{
IList cached = (IList) this.methodCache[method];
if (cached == null)
{
// recalculate...
cached = AdvisorChainFactoryUtils.CalculateInterceptors(advised, proxy, method, targetType);
this.methodCache[method] = cached;
}
return cached;
}
/// <summary>
/// Invoked when the first proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void Activated(AdvisedSupport source)
{
}
/// <summary>
/// Invoked when advice is changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void AdviceChanged(AdvisedSupport source)
{
methodCache.Clear();
}
/// <summary>
/// Invoked when interfaces are changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
public void InterfacesChanged(AdvisedSupport source)
{
}
}
}

View File

@@ -1,500 +1,499 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
using Spring.Aop;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Configuration data for an AOP proxy factory.
/// </summary>
/// <remarks>
/// <p>
/// This configuration includes the
/// <see cref="AopAlliance.Intercept.IInterceptor"/>s,
/// <see cref="Spring.Aop.IAdvisor"/>s, and (any) proxied interfaces.
/// </p>
/// <p>
/// Any AOP proxy obtained from Spring.NET can be cast to this interface to
/// allow the manipulation of said proxy's AOP advice.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvised.cs,v 1.15 2007/10/10 18:07:38 markpollack Exp $</version>
/// <seealso cref="Spring.Aop.Framework.AdvisedSupport"/>
[ProxyIgnore]
public interface IAdvised
{
/// <summary>
/// Should proxies obtained from this configuration expose
/// the AOP proxy to the
/// <see cref="Spring.Aop.Framework.AopContext"/> class?
/// </summary>
/// <remarks>
/// <p>
/// This is useful if an advised object needs to call another advised
/// method on itself. (If it uses the <c>this</c> reference (<c>Me</c>
/// in Visual Basic.NET), the invocation will <b>not</b> be advised).
/// </p>
/// </remarks>
bool ExposeProxy { get; }
/// <summary>
/// Gets the
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/>
/// implementation that will be used to get the interceptor
/// chains for the advised
/// <see cref="Spring.Aop.Framework.AdvisedSupport.Target"/>.
/// </summary>
/// <value>
/// The <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/>
/// implementation that will be used to get the interceptor
/// chains for the advised
/// <see cref="Spring.Aop.Framework.AdvisedSupport.Target"/>.
/// </value>
IAdvisorChainFactory AdvisorChainFactory { get; }
/// <summary>
/// Is the target <see cref="System.Type"/> to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
bool ProxyTargetType { get; }
/// <summary>
/// Is target type attributes, method attributes, method's return type attributes
/// and method's parameter attributes to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
bool ProxyTargetAttributes { get; }
/// <summary>
/// Returns the collection of <see cref="Spring.Aop.IAdvisor"/>
/// instances that have been applied to this proxy.
/// </summary>
/// <remarks>
/// <p>
/// Will never return <cref lang="null"/>, but may return an
/// empty array (in the case where no
/// <see cref="Spring.Aop.IAdvisor"/> instances have been applied to
/// this proxy).
/// </p>
/// </remarks>
/// <value>
/// The collection of <see cref="Spring.Aop.IAdvisor"/>
/// instances that have been applied to this proxy.
/// </value>
IAdvisor[] Advisors { get; }
/// <summary>
/// Returns the collection of <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// instances that have been applied to this proxy.
/// </summary>
/// <remarks>
/// <p>
/// Will never return <cref lang="null"/>, but may return an
/// empty array (in the case where no
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> instances have been
/// applied to this proxy).
/// </p>
/// </remarks>
/// <value>
/// The collection of <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// instances that have been applied to this proxy.
/// </value>
IIntroductionAdvisor[] Introductions { get; }
/// <summary>
/// Returns the collection of interface <see cref="System.Type"/>s
/// to be (or that are being) proxied by this proxy.
/// </summary>
/// <value>
/// The collection of interface <see cref="System.Type"/>s
/// to be (or that are being) proxied by this proxy.
/// </value>
Type[] Interfaces { get; }
/// <summary>
/// Returns the mapping of the proxied interface
/// <see cref="System.Type"/>s to their delegates.
/// </summary>
/// <value>
/// The mapping of the proxied interface
/// <see cref="System.Type"/>s to their delegates.
/// </value>
IDictionary InterfaceMap { get; }
/// <summary>
/// Is this configuration frozen?
/// </summary>
/// <remarks>
/// <p>
/// When a config is frozen, no advice changes can be made. This is
/// useful for optimization, and useful when we don't want callers
/// to be able to manipulate configuration after casting to
/// <see cref="Spring.Aop.Framework.IAdvised"/>.
/// </p>
/// </remarks>
bool IsFrozen { get; }
/// <summary>
/// Returns the <see cref="Spring.Aop.ITargetSource"/> used by this
/// <see cref="Spring.Aop.Framework.IAdvised"/> object.
/// </summary>
/// <value>
/// The <see cref="Spring.Aop.ITargetSource"/> used by this
/// <see cref="Spring.Aop.Framework.IAdvised"/> object.
/// </value>
ITargetSource TargetSource { get; }
/// <summary>
/// Returns a boolean specifying if this <see cref="IAdvised"/>
/// instance can be serialized.
/// </summary>
/// <value>
/// <c>true</c> if this instance can be serialized, <c>false</c> otherwise.
/// </value>
bool IsSerializable { get; }
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the end (or tail)
/// of the advice (interceptor) chain.
/// </summary>
/// <remarks>
/// <p>
/// Please be aware that Spring.NET's AOP implementation only supports
/// method advice (as encapsulated by the
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface).
/// </p>
/// </remarks>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(int,IAdvice)"/>
void AddAdvice(IAdvice advice);
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the supplied
/// <paramref name="position"/> in the advice (interceptor) chain.
/// </summary>
/// <remarks>
/// <p>
/// Please be aware that Spring.NET's AOP implementation only supports
/// method advice (as encapsulated by the
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface).
/// </p>
/// </remarks>
/// <param name="position">
/// The zero (0) indexed position (from the head) at which the
/// supplied <paramref name="advice"/> is to be inserted into the
/// advice (interceptor) chain.
/// </param>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(IAdvice)"/>
void AddAdvice(int position, IAdvice advice);
/// <summary>
/// Is the supplied <paramref name="intf"/> (interface)
/// <see cref="System.Type"/> proxied?
/// </summary>
/// <param name="intf">
/// The interface <see cref="System.Type"/> to test.
/// </param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="intf"/>
/// (interface) <see cref="System.Type"/> is proxied;
/// <see langword="false"/> if not or the supplied
/// <paramref name="intf"/> is <cref lang="null"/>.
/// </returns>
bool IsInterfaceProxied(Type intf);
/// <summary>
/// Adds the advisors from the supplied <paramref name="advisors"/>
/// to the list of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="advisors">
/// The <see cref="IAdvisors"/> to add advisors from.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <paramref name="advisors"/> cannot be added.
/// </exception>
void AddAdvisors(IAdvisors advisors);
/// <summary>
/// Adds the supplied <paramref name="advisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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>
void AddAdvisor(IAdvisor advisor);
/// <summary>
/// Adds the supplied <paramref name="advisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="index">
/// The index in the <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// list at which the supplied <paramref name="advisor"/>
/// is to be inserted.
/// </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>
void AddAdvisor(int index, IAdvisor advisor);
/// <summary>
/// Adds the supplied <paramref name="introductionAdvisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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>
void AddIntroduction(IIntroductionAdvisor introductionAdvisor);
/// <summary>
/// Adds the supplied <paramref name="introductionAdvisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Introductions"/>.
/// </summary>
/// <param name="index">
/// The index in the <see cref="Spring.Aop.Framework.IAdvised.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>
void AddIntroduction(int index, IIntroductionAdvisor introductionAdvisor);
/// <summary>
/// Return the index (0 based) of the supplied
/// <see cref="Spring.Aop.IAdvisor"/> in the interceptor
/// (advice) chain for this proxy.
/// </summary>
/// <remarks>
/// <p>
/// The return value of this method can be used to index into
/// the <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// list.
/// </p>
/// </remarks>
/// <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>
int IndexOf(IAdvisor advisor);
/// <summary>
/// Return the index (0 based) of the supplied
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> in the introductions
/// for this proxy.
/// </summary>
/// <remarks>
/// <p>
/// The return value of this method can be used to index into
/// the <see cref="Spring.Aop.Framework.IAdvised.Introductions"/>
/// list.
/// </p>
/// </remarks>
/// <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>
int IndexOf(IIntroductionAdvisor advisor);
/// <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.IAdvised.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>
bool RemoveAdvisor(IAdvisor advisor);
/// <summary>
/// Removes the <see cref="Spring.Aop.IAdvisor"/> at the supplied
/// <paramref name="index"/> in the
/// <see cref="Spring.Aop.Framework.IAdvised.Advisors"/> list
/// from the list of
/// <see cref="Spring.Aop.Framework.IAdvised.Advisors"/> for this proxy.
/// </summary>
/// <param name="index">
/// The index of the <see cref="Spring.Aop.IAdvisor"/> to remove.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="Spring.Aop.IAdvisor"/> at the supplied <paramref name="index"/>
/// cannot be removed; or if the supplied <paramref name="index"/> is out of
/// range.
/// </exception>
void RemoveAdvisor(int index);
/// <summary>
/// Removes the supplied <paramref name="advice"/> from the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to remove.
/// </param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> was
/// found in the list of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// and successfully removed.
/// </returns>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="AopAlliance.Aop.IAdvice"/> cannot be removed.
/// </exception>
bool RemoveAdvice(IAdvice advice);
/// <summary>
/// Removes the supplied <paramref name="introduction"/> from the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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.IAdvised.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>
bool RemoveIntroduction(IIntroductionAdvisor introduction);
/// <summary>
/// Removes the <see cref="Spring.Aop.IIntroductionAdvisor"/> at the supplied
/// <paramref name="index"/> in the list of
/// <see cref="Spring.Aop.Framework.IAdvised.Introductions"/> for this proxy.
/// </summary>
/// <param name="index">The index of the advisor to remove.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> at the supplied
/// <paramref name="index"/> cannot be removed; or if the supplied
/// <paramref name="index"/> is out of range.
/// </exception>
void RemoveIntroduction(int index);
/// <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.IAdvised.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.IAdvised.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>
void ReplaceIntroduction(int index, IIntroductionAdvisor introduction);
/// <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, 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"/>
bool ReplaceAdvisor(IAdvisor oldAdvisor, IAdvisor newAdvisor);
/// <summary>
/// As <see cref="System.Object.ToString()"/> will normally be passed
/// straight through to the advised target, this method returns the
/// <see cref="System.Object.ToString()"/> equivalent for the AOP
/// proxy itself.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> description of the proxy configuration.
/// </returns>
string ToProxyConfigString();
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
using Spring.Aop;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Configuration data for an AOP proxy factory.
/// </summary>
/// <remarks>
/// <p>
/// This configuration includes the
/// <see cref="AopAlliance.Intercept.IInterceptor"/>s,
/// <see cref="Spring.Aop.IAdvisor"/>s, and (any) proxied interfaces.
/// </p>
/// <p>
/// Any AOP proxy obtained from Spring.NET can be cast to this interface to
/// allow the manipulation of said proxy's AOP advice.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.Framework.AdvisedSupport"/>
[ProxyIgnore]
public interface IAdvised
{
/// <summary>
/// Should proxies obtained from this configuration expose
/// the AOP proxy to the
/// <see cref="Spring.Aop.Framework.AopContext"/> class?
/// </summary>
/// <remarks>
/// <p>
/// This is useful if an advised object needs to call another advised
/// method on itself. (If it uses the <c>this</c> reference (<c>Me</c>
/// in Visual Basic.NET), the invocation will <b>not</b> be advised).
/// </p>
/// </remarks>
bool ExposeProxy { get; }
/// <summary>
/// Gets the
/// <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/>
/// implementation that will be used to get the interceptor
/// chains for the advised
/// <see cref="Spring.Aop.Framework.AdvisedSupport.Target"/>.
/// </summary>
/// <value>
/// The <see cref="Spring.Aop.Framework.IAdvisorChainFactory"/>
/// implementation that will be used to get the interceptor
/// chains for the advised
/// <see cref="Spring.Aop.Framework.AdvisedSupport.Target"/>.
/// </value>
IAdvisorChainFactory AdvisorChainFactory { get; }
/// <summary>
/// Is the target <see cref="System.Type"/> to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
bool ProxyTargetType { get; }
/// <summary>
/// Is target type attributes, method attributes, method's return type attributes
/// and method's parameter attributes to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
bool ProxyTargetAttributes { get; }
/// <summary>
/// Returns the collection of <see cref="Spring.Aop.IAdvisor"/>
/// instances that have been applied to this proxy.
/// </summary>
/// <remarks>
/// <p>
/// Will never return <cref lang="null"/>, but may return an
/// empty array (in the case where no
/// <see cref="Spring.Aop.IAdvisor"/> instances have been applied to
/// this proxy).
/// </p>
/// </remarks>
/// <value>
/// The collection of <see cref="Spring.Aop.IAdvisor"/>
/// instances that have been applied to this proxy.
/// </value>
IAdvisor[] Advisors { get; }
/// <summary>
/// Returns the collection of <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// instances that have been applied to this proxy.
/// </summary>
/// <remarks>
/// <p>
/// Will never return <cref lang="null"/>, but may return an
/// empty array (in the case where no
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> instances have been
/// applied to this proxy).
/// </p>
/// </remarks>
/// <value>
/// The collection of <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// instances that have been applied to this proxy.
/// </value>
IIntroductionAdvisor[] Introductions { get; }
/// <summary>
/// Returns the collection of interface <see cref="System.Type"/>s
/// to be (or that are being) proxied by this proxy.
/// </summary>
/// <value>
/// The collection of interface <see cref="System.Type"/>s
/// to be (or that are being) proxied by this proxy.
/// </value>
Type[] Interfaces { get; }
/// <summary>
/// Returns the mapping of the proxied interface
/// <see cref="System.Type"/>s to their delegates.
/// </summary>
/// <value>
/// The mapping of the proxied interface
/// <see cref="System.Type"/>s to their delegates.
/// </value>
IDictionary InterfaceMap { get; }
/// <summary>
/// Is this configuration frozen?
/// </summary>
/// <remarks>
/// <p>
/// When a config is frozen, no advice changes can be made. This is
/// useful for optimization, and useful when we don't want callers
/// to be able to manipulate configuration after casting to
/// <see cref="Spring.Aop.Framework.IAdvised"/>.
/// </p>
/// </remarks>
bool IsFrozen { get; }
/// <summary>
/// Returns the <see cref="Spring.Aop.ITargetSource"/> used by this
/// <see cref="Spring.Aop.Framework.IAdvised"/> object.
/// </summary>
/// <value>
/// The <see cref="Spring.Aop.ITargetSource"/> used by this
/// <see cref="Spring.Aop.Framework.IAdvised"/> object.
/// </value>
ITargetSource TargetSource { get; }
/// <summary>
/// Returns a boolean specifying if this <see cref="IAdvised"/>
/// instance can be serialized.
/// </summary>
/// <value>
/// <c>true</c> if this instance can be serialized, <c>false</c> otherwise.
/// </value>
bool IsSerializable { get; }
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the end (or tail)
/// of the advice (interceptor) chain.
/// </summary>
/// <remarks>
/// <p>
/// Please be aware that Spring.NET's AOP implementation only supports
/// method advice (as encapsulated by the
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface).
/// </p>
/// </remarks>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(int,IAdvice)"/>
void AddAdvice(IAdvice advice);
/// <summary>
/// Adds the supplied <paramref name="advice"/> to the supplied
/// <paramref name="position"/> in the advice (interceptor) chain.
/// </summary>
/// <remarks>
/// <p>
/// Please be aware that Spring.NET's AOP implementation only supports
/// method advice (as encapsulated by the
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface).
/// </p>
/// </remarks>
/// <param name="position">
/// The zero (0) indexed position (from the head) at which the
/// supplied <paramref name="advice"/> is to be inserted into the
/// advice (interceptor) chain.
/// </param>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to be added.
/// </param>
/// <seealso cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// <seealso cref="Spring.Aop.Framework.IAdvised.AddAdvice(IAdvice)"/>
void AddAdvice(int position, IAdvice advice);
/// <summary>
/// Is the supplied <paramref name="intf"/> (interface)
/// <see cref="System.Type"/> proxied?
/// </summary>
/// <param name="intf">
/// The interface <see cref="System.Type"/> to test.
/// </param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="intf"/>
/// (interface) <see cref="System.Type"/> is proxied;
/// <see langword="false"/> if not or the supplied
/// <paramref name="intf"/> is <cref lang="null"/>.
/// </returns>
bool IsInterfaceProxied(Type intf);
/// <summary>
/// Adds the advisors from the supplied <paramref name="advisors"/>
/// to the list of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="advisors">
/// The <see cref="IAdvisors"/> to add advisors from.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <paramref name="advisors"/> cannot be added.
/// </exception>
void AddAdvisors(IAdvisors advisors);
/// <summary>
/// Adds the supplied <paramref name="advisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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>
void AddAdvisor(IAdvisor advisor);
/// <summary>
/// Adds the supplied <paramref name="advisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="index">
/// The index in the <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// list at which the supplied <paramref name="advisor"/>
/// is to be inserted.
/// </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>
void AddAdvisor(int index, IAdvisor advisor);
/// <summary>
/// Adds the supplied <paramref name="introductionAdvisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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>
void AddIntroduction(IIntroductionAdvisor introductionAdvisor);
/// <summary>
/// Adds the supplied <paramref name="introductionAdvisor"/> to the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Introductions"/>.
/// </summary>
/// <param name="index">
/// The index in the <see cref="Spring.Aop.Framework.IAdvised.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>
void AddIntroduction(int index, IIntroductionAdvisor introductionAdvisor);
/// <summary>
/// Return the index (0 based) of the supplied
/// <see cref="Spring.Aop.IAdvisor"/> in the interceptor
/// (advice) chain for this proxy.
/// </summary>
/// <remarks>
/// <p>
/// The return value of this method can be used to index into
/// the <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// list.
/// </p>
/// </remarks>
/// <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>
int IndexOf(IAdvisor advisor);
/// <summary>
/// Return the index (0 based) of the supplied
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> in the introductions
/// for this proxy.
/// </summary>
/// <remarks>
/// <p>
/// The return value of this method can be used to index into
/// the <see cref="Spring.Aop.Framework.IAdvised.Introductions"/>
/// list.
/// </p>
/// </remarks>
/// <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>
int IndexOf(IIntroductionAdvisor advisor);
/// <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.IAdvised.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>
bool RemoveAdvisor(IAdvisor advisor);
/// <summary>
/// Removes the <see cref="Spring.Aop.IAdvisor"/> at the supplied
/// <paramref name="index"/> in the
/// <see cref="Spring.Aop.Framework.IAdvised.Advisors"/> list
/// from the list of
/// <see cref="Spring.Aop.Framework.IAdvised.Advisors"/> for this proxy.
/// </summary>
/// <param name="index">
/// The index of the <see cref="Spring.Aop.IAdvisor"/> to remove.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="Spring.Aop.IAdvisor"/> at the supplied <paramref name="index"/>
/// cannot be removed; or if the supplied <paramref name="index"/> is out of
/// range.
/// </exception>
void RemoveAdvisor(int index);
/// <summary>
/// Removes the supplied <paramref name="advice"/> from the list
/// of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>.
/// </summary>
/// <param name="advice">
/// The <see cref="AopAlliance.Aop.IAdvice"/> to remove.
/// </param>
/// <returns>
/// <see langword="true"/> if the supplied <paramref name="advice"/> was
/// found in the list of <see cref="Spring.Aop.Framework.IAdvised.Advisors"/>
/// and successfully removed.
/// </returns>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="AopAlliance.Aop.IAdvice"/> cannot be removed.
/// </exception>
bool RemoveAdvice(IAdvice advice);
/// <summary>
/// Removes the supplied <paramref name="introduction"/> from the list
/// of <see cref="Spring.Aop.Framework.IAdvised.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.IAdvised.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>
bool RemoveIntroduction(IIntroductionAdvisor introduction);
/// <summary>
/// Removes the <see cref="Spring.Aop.IIntroductionAdvisor"/> at the supplied
/// <paramref name="index"/> in the list of
/// <see cref="Spring.Aop.Framework.IAdvised.Introductions"/> for this proxy.
/// </summary>
/// <param name="index">The index of the advisor to remove.
/// </param>
/// <exception cref="AopConfigException">
/// If this proxy configuration is frozen and the
/// <see cref="Spring.Aop.IIntroductionAdvisor"/> at the supplied
/// <paramref name="index"/> cannot be removed; or if the supplied
/// <paramref name="index"/> is out of range.
/// </exception>
void RemoveIntroduction(int index);
/// <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.IAdvised.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.IAdvised.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>
void ReplaceIntroduction(int index, IIntroductionAdvisor introduction);
/// <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, 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"/>
bool ReplaceAdvisor(IAdvisor oldAdvisor, IAdvisor newAdvisor);
/// <summary>
/// As <see cref="System.Object.ToString()"/> will normally be passed
/// straight through to the advised target, this method returns the
/// <see cref="System.Object.ToString()"/> equivalent for the AOP
/// proxy itself.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> description of the proxy configuration.
/// </returns>
string ToProxyConfigString();
}
}

View File

@@ -1,66 +1,65 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Callback interface for
/// <see cref="Spring.Aop.Framework.AdvisedSupport"/> listeners.
/// </summary>
/// <remarks>
/// <p>
/// Allows <see cref="Spring.Aop.Framework.IAdvisedSupportListener"/>
/// implementations to be notified of notable lifecycle events relating
/// to the creation of a proxy, and changes to the configuration data of a
/// proxy.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvisedSupportListener.cs,v 1.5 2006/04/09 07:18:35 markpollack Exp $</version>
public interface IAdvisedSupportListener
{
/// <summary>
/// Invoked when the first proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void Activated(AdvisedSupport source);
/// <summary>
/// Invoked when advice is changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void AdviceChanged(AdvisedSupport source);
/// <summary>
/// Invoked when interfaces are changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void InterfacesChanged(AdvisedSupport source);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Callback interface for
/// <see cref="Spring.Aop.Framework.AdvisedSupport"/> listeners.
/// </summary>
/// <remarks>
/// <p>
/// Allows <see cref="Spring.Aop.Framework.IAdvisedSupportListener"/>
/// implementations to be notified of notable lifecycle events relating
/// to the creation of a proxy, and changes to the configuration data of a
/// proxy.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAdvisedSupportListener
{
/// <summary>
/// Invoked when the first proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void Activated(AdvisedSupport source);
/// <summary>
/// Invoked when advice is changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void AdviceChanged(AdvisedSupport source);
/// <summary>
/// Invoked when interfaces are changed after a proxy is created.
/// </summary>
/// <param name="source">
/// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source.
/// </param>
void InterfacesChanged(AdvisedSupport source);
}
}

View File

@@ -1,60 +1,59 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory interface for advisor chains.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvisorChainFactory.cs,v 1.8 2006/09/14 21:05:23 bbaia Exp $</version>
public interface IAdvisorChainFactory : IAdvisedSupportListener
{
/// <summary>
/// Gets the list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </summary>
/// <param name="advised">The proxy configuration object.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method for which the interceptors are to be evaluated.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// The list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </returns>
IList GetInterceptors(
IAdvised advised, object proxy, MethodInfo method, Type targetType);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory interface for advisor chains.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAdvisorChainFactory : IAdvisedSupportListener
{
/// <summary>
/// Gets the list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </summary>
/// <param name="advised">The proxy configuration object.</param>
/// <param name="proxy">The object proxy.</param>
/// <param name="method">
/// The method for which the interceptors are to be evaluated.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.
/// </param>
/// <returns>
/// The list of <see cref="AopAlliance.Intercept.IInterceptor"/> and
/// <see cref="Spring.Aop.Framework.InterceptorAndDynamicMethodMatcher"/>
/// instances for the supplied <paramref name="proxy"/>.
/// </returns>
IList GetInterceptors(
IAdvised advised, object proxy, MethodInfo method, Type targetType);
}
}

View File

@@ -1,45 +1,44 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// The central interface for Spring.NET based AOP proxies.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAopProxy.cs,v 1.4 2006/11/16 02:30:49 bbaia Exp $</version>
[ProxyIgnore]
public interface IAopProxy
{
/// <summary>
/// Creates a new proxy object.
/// </summary>
object GetProxy();
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Proxy;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// The central interface for Spring.NET based AOP proxies.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[ProxyIgnore]
public interface IAopProxy
{
/// <summary>
/// Creates a new proxy object.
/// </summary>
object GetProxy();
}
}

View File

@@ -1,47 +1,46 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory interface for the creation of AOP proxies based on
/// <see cref="Spring.Aop.Framework.AdvisedSupport"/> configuration
/// objects.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAopProxyFactory.cs,v 1.3 2006/04/09 07:18:35 markpollack Exp $</version>
public interface IAopProxyFactory
{
/// <summary>
/// Creates an <see cref="Spring.Aop.Framework.IAopProxy"/> for the
/// supplied <paramref name="advisedSupport"/> configuration.
/// </summary>
/// <param name="advisedSupport">The AOP configuration.</param>
/// <returns>An <see cref="Spring.Aop.Framework.IAopProxy"/>.</returns>
/// <exception cref="AopConfigException">
/// If the supplied <paramref name="advisedSupport"/> configuration is
/// invalid.
/// </exception>
IAopProxy CreateAopProxy(AdvisedSupport advisedSupport);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory interface for the creation of AOP proxies based on
/// <see cref="Spring.Aop.Framework.AdvisedSupport"/> configuration
/// objects.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAopProxyFactory
{
/// <summary>
/// Creates an <see cref="Spring.Aop.Framework.IAopProxy"/> for the
/// supplied <paramref name="advisedSupport"/> configuration.
/// </summary>
/// <param name="advisedSupport">The AOP configuration.</param>
/// <returns>An <see cref="Spring.Aop.Framework.IAopProxy"/>.</returns>
/// <exception cref="AopConfigException">
/// If the supplied <paramref name="advisedSupport"/> configuration is
/// invalid.
/// </exception>
IAopProxy CreateAopProxy(AdvisedSupport advisedSupport);
}
}

View File

@@ -1,46 +1,45 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Provides access to the target object of an AOP proxy.
/// </summary>
/// <remarks>
/// <p>
/// To be implemented by introduction aspects in order to obtain access to
/// the target object.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: ITargetAware.cs,v 1.3 2006/04/09 07:18:35 markpollack Exp $</version>
public interface ITargetAware
{
/// <summary>
/// Sets the <see cref="Spring.Aop.Framework.IAopProxy"/> target object.
/// </summary>
IAopProxy TargetProxy
{
set;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Provides access to the target object of an AOP proxy.
/// </summary>
/// <remarks>
/// <p>
/// To be implemented by introduction aspects in order to obtain access to
/// the target object.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
public interface ITargetAware
{
/// <summary>
/// Sets the <see cref="Spring.Aop.Framework.IAopProxy"/> target object.
/// </summary>
IAopProxy TargetProxy
{
set;
}
}
}

View File

@@ -1,39 +1,38 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: ITargetSourceWrapper.cs,v 1.1 2006/08/10 18:45:52 bbaia Exp $</version>
public interface ITargetSourceWrapper : IDisposable
{
/// <summary>
/// Returns the target object that proxy methods will be delegated to.
/// </summary>
/// <returns>The target object.</returns>
object GetTarget();
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <author>Aleksandar Seovic</author>
public interface ITargetSourceWrapper : IDisposable
{
/// <summary>
/// Returns the target object that proxy methods will be delegated to.
/// </summary>
/// <returns>The target object.</returns>
object GetTarget();
}
}

View File

@@ -1,48 +1,47 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Intercept;
using Spring.Aop;
namespace Spring.Aop.Framework
{
/// <summary> Internal framework class.
/// This class is required because if we put an interceptor that implements IInterceptionAdvice
/// in the interceptor list passed to MethodInvocation, it may be mistaken for an
/// advice that requires dynamic method matching.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
/// <version>$Id: InterceptorAndDynamicMethodMatcher.cs,v 1.3 2007/03/16 04:01:18 aseovic Exp $</version>
[Serializable]
internal class InterceptorAndDynamicMethodMatcher
{
internal IMethodMatcher MethodMatcher;
internal IMethodInterceptor Interceptor;
public InterceptorAndDynamicMethodMatcher(IMethodInterceptor interceptor, IMethodMatcher methodMatcher)
{
this.Interceptor = interceptor;
this.MethodMatcher = methodMatcher;
}
}
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Intercept;
using Spring.Aop;
namespace Spring.Aop.Framework
{
/// <summary> Internal framework class.
/// This class is required because if we put an interceptor that implements IInterceptionAdvice
/// in the interceptor list passed to MethodInvocation, it may be mistaken for an
/// advice that requires dynamic method matching.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
[Serializable]
internal class InterceptorAndDynamicMethodMatcher
{
internal IMethodMatcher MethodMatcher;
internal IMethodInterceptor Interceptor;
public InterceptorAndDynamicMethodMatcher(IMethodInterceptor interceptor, IMethodMatcher methodMatcher)
{
this.Interceptor = interceptor;
this.MethodMatcher = methodMatcher;
}
}
}

View File

@@ -1,222 +1,221 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Text;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Core.TypeResolution;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Convenience superclass for configuration used in creating proxies,
/// to ensure that all proxy creators have consistent properties.
/// </summary>
/// <remarks>
/// <p>
/// Note that it is no longer possible to configure subclasses to
/// expose the <see cref="AopAlliance.Intercept.IMethodInvocation"/>.
/// Interceptors should normally manage their own thread locals if they
/// need to make resources available to advised objects. If it is
/// absolutely necessary to expose the
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/>, use an
/// interceptor to do so.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ProxyConfig.cs,v 1.13 2007/09/07 01:51:49 markpollack Exp $</version>
[Serializable]
public class ProxyConfig
{
#region Fields
private bool proxyTargetType;
private bool proxyTargetAttributes = true;
private bool optimize;
private bool frozen;
private IAopProxyFactory aopProxyFactory =
ObjectUtils.InstantiateType( typeof(ProxyConfig).Assembly, "Spring.Aop.Framework.DynamicProxy.CachedAopProxyFactory") as IAopProxyFactory;
private bool exposeProxy;
private object syncRoot = new object();
#endregion
#region Properites
/// <summary>
/// Use to synchronize access to this ProxyConfig instance
/// </summary>
public object SyncRoot
{
get { return syncRoot; }
}
/// <summary>
/// Is the target <see cref="System.Type"/> to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
public virtual bool ProxyTargetType
{
get { return this.proxyTargetType; }
set { this.proxyTargetType = value; }
}
/// <summary>
/// Is target type attributes, method attributes, method's return type attributes
/// and method's parameter attributes to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
public virtual bool ProxyTargetAttributes
{
get { return this.proxyTargetAttributes; }
set { this.proxyTargetAttributes = value; }
}
/// <summary>
/// Are any <i>agressive optimizations</i> to be performed?
/// </summary>
/// <remarks>
/// <p>
/// The exact meaning of <i>agressive optimizations</i> will differ
/// between proxies, but there is usually some tradeoff.
/// </p>
/// <p>
/// For example, optimization will usually mean that advice changes
/// won't take effect after a proxy has been created. For this reason,
/// optimization is disabled by default. An optimize value of
/// <see langword="true"/> may be ignored if other settings preclude
/// optimization: for example, if the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// is set to <see langword="true"/> and such a value is not compatible
/// with the optimization.
/// </p>
/// <p>
/// The default is <see langword="false"/>.
/// </p>
/// </remarks>
public virtual bool Optimize
{
get { return this.optimize; }
set { this.optimize = value; }
}
/// <summary>
/// Should proxies obtained from this configuration expose
/// the AOP proxy to the
/// <see cref="Spring.Aop.Framework.AopContext"/> class?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="false"/>, as enabling this property
/// may impair performance.
/// </p>
/// </remarks>
public bool ExposeProxy
{
get { return this.exposeProxy; }
set { this.exposeProxy = value; }
}
/// <summary>
/// Gets and set the factory to be used to create AOP proxies.
/// </summary>
/// <remarks>
/// <p>
/// This obviously allows one to customise the
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> implementation,
/// allowing different strategies to be dropped in without changing the
/// core framework. For example, an
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> implementation
/// could return an <see cref="Spring.Aop.Framework.IAopProxy"/>
/// using remoting proxies, <c>Reflection.Emit</c> or a code generation
/// strategy.
/// </p>
/// </remarks>
public virtual IAopProxyFactory AopProxyFactory
{
get { return this.aopProxyFactory; }
set { this.aopProxyFactory = value; }
}
/// <summary>
/// Is this configuration frozen?
/// </summary>
/// <remarks>
/// <p>
/// The default is not frozen.
/// </p>
/// </remarks>
public virtual bool IsFrozen
{
get { return frozen; }
set { this.frozen = value; }
}
#endregion
/// <summary>
/// Copies the configuration from the supplied
/// <paramref name="otherConfiguration"/> into this instance.
/// </summary>
/// <param name="otherConfiguration">
/// The configuration to be copied.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="otherConfiguration"/> is
/// <see langword="null"/>.
/// </exception>
public virtual void CopyFrom(ProxyConfig otherConfiguration)
{
AssertUtils.ArgumentNotNull(otherConfiguration, "otherConfiguration");
this.optimize = otherConfiguration.optimize;
this.proxyTargetType = otherConfiguration.proxyTargetType;
this.proxyTargetAttributes = otherConfiguration.proxyTargetAttributes;
this.exposeProxy = otherConfiguration.exposeProxy;
this.frozen = otherConfiguration.frozen;
this.aopProxyFactory = otherConfiguration.aopProxyFactory;
}
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.Framework.ProxyConfig"/> configuration.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.Framework.ProxyConfig"/> configuration.
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("proxyTargetType=" + ProxyTargetType + "; ");
buffer.Append("proxyTargetAttributes=" + ProxyTargetAttributes + "; ");
buffer.Append("exposeProxy=" + ExposeProxy + "; ");
buffer.Append("isFrozen=" + IsFrozen + "; ");
buffer.Append("optimize=" + Optimize + "; ");
buffer.Append("aopProxyFactory=" + AopProxyFactory.GetType().FullName + "; ");
return buffer.ToString();
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Text;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Core.TypeResolution;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Convenience superclass for configuration used in creating proxies,
/// to ensure that all proxy creators have consistent properties.
/// </summary>
/// <remarks>
/// <p>
/// Note that it is no longer possible to configure subclasses to
/// expose the <see cref="AopAlliance.Intercept.IMethodInvocation"/>.
/// Interceptors should normally manage their own thread locals if they
/// need to make resources available to advised objects. If it is
/// absolutely necessary to expose the
/// <see cref="AopAlliance.Intercept.IMethodInvocation"/>, use an
/// interceptor to do so.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class ProxyConfig
{
#region Fields
private bool proxyTargetType;
private bool proxyTargetAttributes = true;
private bool optimize;
private bool frozen;
private IAopProxyFactory aopProxyFactory =
ObjectUtils.InstantiateType( typeof(ProxyConfig).Assembly, "Spring.Aop.Framework.DynamicProxy.CachedAopProxyFactory") as IAopProxyFactory;
private bool exposeProxy;
private object syncRoot = new object();
#endregion
#region Properites
/// <summary>
/// Use to synchronize access to this ProxyConfig instance
/// </summary>
public object SyncRoot
{
get { return syncRoot; }
}
/// <summary>
/// Is the target <see cref="System.Type"/> to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
public virtual bool ProxyTargetType
{
get { return this.proxyTargetType; }
set { this.proxyTargetType = value; }
}
/// <summary>
/// Is target type attributes, method attributes, method's return type attributes
/// and method's parameter attributes to be proxied in addition
/// to any interfaces declared on the proxied <see cref="System.Type"/>?
/// </summary>
public virtual bool ProxyTargetAttributes
{
get { return this.proxyTargetAttributes; }
set { this.proxyTargetAttributes = value; }
}
/// <summary>
/// Are any <i>agressive optimizations</i> to be performed?
/// </summary>
/// <remarks>
/// <p>
/// The exact meaning of <i>agressive optimizations</i> will differ
/// between proxies, but there is usually some tradeoff.
/// </p>
/// <p>
/// For example, optimization will usually mean that advice changes
/// won't take effect after a proxy has been created. For this reason,
/// optimization is disabled by default. An optimize value of
/// <see langword="true"/> may be ignored if other settings preclude
/// optimization: for example, if the
/// <see cref="Spring.Aop.Framework.ProxyConfig.ExposeProxy"/> property
/// is set to <see langword="true"/> and such a value is not compatible
/// with the optimization.
/// </p>
/// <p>
/// The default is <see langword="false"/>.
/// </p>
/// </remarks>
public virtual bool Optimize
{
get { return this.optimize; }
set { this.optimize = value; }
}
/// <summary>
/// Should proxies obtained from this configuration expose
/// the AOP proxy to the
/// <see cref="Spring.Aop.Framework.AopContext"/> class?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="false"/>, as enabling this property
/// may impair performance.
/// </p>
/// </remarks>
public bool ExposeProxy
{
get { return this.exposeProxy; }
set { this.exposeProxy = value; }
}
/// <summary>
/// Gets and set the factory to be used to create AOP proxies.
/// </summary>
/// <remarks>
/// <p>
/// This obviously allows one to customise the
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> implementation,
/// allowing different strategies to be dropped in without changing the
/// core framework. For example, an
/// <see cref="Spring.Aop.Framework.IAopProxyFactory"/> implementation
/// could return an <see cref="Spring.Aop.Framework.IAopProxy"/>
/// using remoting proxies, <c>Reflection.Emit</c> or a code generation
/// strategy.
/// </p>
/// </remarks>
public virtual IAopProxyFactory AopProxyFactory
{
get { return this.aopProxyFactory; }
set { this.aopProxyFactory = value; }
}
/// <summary>
/// Is this configuration frozen?
/// </summary>
/// <remarks>
/// <p>
/// The default is not frozen.
/// </p>
/// </remarks>
public virtual bool IsFrozen
{
get { return frozen; }
set { this.frozen = value; }
}
#endregion
/// <summary>
/// Copies the configuration from the supplied
/// <paramref name="otherConfiguration"/> into this instance.
/// </summary>
/// <param name="otherConfiguration">
/// The configuration to be copied.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="otherConfiguration"/> is
/// <see langword="null"/>.
/// </exception>
public virtual void CopyFrom(ProxyConfig otherConfiguration)
{
AssertUtils.ArgumentNotNull(otherConfiguration, "otherConfiguration");
this.optimize = otherConfiguration.optimize;
this.proxyTargetType = otherConfiguration.proxyTargetType;
this.proxyTargetAttributes = otherConfiguration.proxyTargetAttributes;
this.exposeProxy = otherConfiguration.exposeProxy;
this.frozen = otherConfiguration.frozen;
this.aopProxyFactory = otherConfiguration.aopProxyFactory;
}
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.Framework.ProxyConfig"/> configuration.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.Framework.ProxyConfig"/> configuration.
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("proxyTargetType=" + ProxyTargetType + "; ");
buffer.Append("proxyTargetAttributes=" + ProxyTargetAttributes + "; ");
buffer.Append("exposeProxy=" + ExposeProxy + "; ");
buffer.Append("isFrozen=" + IsFrozen + "; ");
buffer.Append("optimize=" + Optimize + "; ");
buffer.Append("aopProxyFactory=" + AopProxyFactory.GetType().FullName + "; ");
return buffer.ToString();
}
}
}

View File

@@ -1,129 +1,128 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory for AOP proxies for programmatic use, rather than via a
/// Spring.NET IoC container.
/// </summary>
/// <remarks>
/// <p>
/// This class provides a simple way of obtaining and configuring AOP
/// proxies in code.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ProxyFactory.cs,v 1.8 2007/03/16 04:01:19 aseovic Exp $</version>
[Serializable]
public class ProxyFactory : AdvisedSupport
{
/// <summary>
/// Creates a new instance of the <see cref="Spring.Aop.Framework.ProxyFactory"/>
/// class.
/// </summary>
public ProxyFactory()
{
}
/// <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="target"/>.
/// </summary>
/// <param name="target">The object to proxy.</param>
/// <exception cref="AopConfigException">
/// If the <paramref name="target"/> is <cref lang="null"/>.
/// </exception>
public ProxyFactory(object target) : base(GetInterfaces(target))
{
Target = target;
}
/// <summary>
/// Creates a new instance of the <see cref="Spring.Aop.Framework.ProxyFactory"/>
/// class that has no target object, only interfaces.
/// </summary>
/// <remarks>
/// <p>
/// Interceptors must be added if this factory is to do anything useful.
/// </p>
/// </remarks>
/// <param name="interfaces">The interfaces to implement.</param>
public ProxyFactory(Type[] interfaces) : base(interfaces) {}
/// <summary>
/// Creates a new proxy according to the settings in this factory.
/// </summary>
/// <remarks>
/// <p>
/// Can be called repeatedly; the effect of repeated invocations will
/// (of course) vary if interfaces have been added or removed.
/// </p>
/// </remarks>
/// <returns>An AOP proxy for target object.</returns>
public virtual object GetProxy()
{
IAopProxy proxy = CreateAopProxy();
return proxy.GetProxy();
}
#region Convenience Methods (Static) For Proxy Creation
/// <summary>
/// Creates a new proxy for the supplied <paramref name="proxyInterface"/>
/// and <paramref name="interceptor"/>.
/// </summary>
/// <remarks>
/// <p>
/// This is a convenience method for creating a proxy for a single
/// interceptor.
/// </p>
/// </remarks>
/// <param name="proxyInterface">
/// The interface that the proxy must implement.
/// </param>
/// <param name="interceptor">
/// The interceptor that the proxy must invoke.
/// </param>
/// <returns>
/// A new AOP proxy for the supplied <paramref name="proxyInterface"/>
/// and <paramref name="interceptor"/>.
/// </returns>
public static object GetProxy(Type proxyInterface, IInterceptor interceptor)
{
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.AddInterface(proxyInterface);
proxyFactory.AddAdvice(interceptor);
return proxyFactory.GetProxy();
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Factory for AOP proxies for programmatic use, rather than via a
/// Spring.NET IoC container.
/// </summary>
/// <remarks>
/// <p>
/// This class provides a simple way of obtaining and configuring AOP
/// proxies in code.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class ProxyFactory : AdvisedSupport
{
/// <summary>
/// Creates a new instance of the <see cref="Spring.Aop.Framework.ProxyFactory"/>
/// class.
/// </summary>
public ProxyFactory()
{
}
/// <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="target"/>.
/// </summary>
/// <param name="target">The object to proxy.</param>
/// <exception cref="AopConfigException">
/// If the <paramref name="target"/> is <cref lang="null"/>.
/// </exception>
public ProxyFactory(object target) : base(GetInterfaces(target))
{
Target = target;
}
/// <summary>
/// Creates a new instance of the <see cref="Spring.Aop.Framework.ProxyFactory"/>
/// class that has no target object, only interfaces.
/// </summary>
/// <remarks>
/// <p>
/// Interceptors must be added if this factory is to do anything useful.
/// </p>
/// </remarks>
/// <param name="interfaces">The interfaces to implement.</param>
public ProxyFactory(Type[] interfaces) : base(interfaces) {}
/// <summary>
/// Creates a new proxy according to the settings in this factory.
/// </summary>
/// <remarks>
/// <p>
/// Can be called repeatedly; the effect of repeated invocations will
/// (of course) vary if interfaces have been added or removed.
/// </p>
/// </remarks>
/// <returns>An AOP proxy for target object.</returns>
public virtual object GetProxy()
{
IAopProxy proxy = CreateAopProxy();
return proxy.GetProxy();
}
#region Convenience Methods (Static) For Proxy Creation
/// <summary>
/// Creates a new proxy for the supplied <paramref name="proxyInterface"/>
/// and <paramref name="interceptor"/>.
/// </summary>
/// <remarks>
/// <p>
/// This is a convenience method for creating a proxy for a single
/// interceptor.
/// </p>
/// </remarks>
/// <param name="proxyInterface">
/// The interface that the proxy must implement.
/// </param>
/// <param name="interceptor">
/// The interceptor that the proxy must invoke.
/// </param>
/// <returns>
/// A new AOP proxy for the supplied <paramref name="proxyInterface"/>
/// and <paramref name="interceptor"/>.
/// </returns>
public static object GetProxy(Type proxyInterface, IInterceptor interceptor)
{
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.AddInterface(proxyInterface);
proxyFactory.AddAdvice(interceptor);
return proxyFactory.GetProxy();
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,131 +1,130 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using Spring.Util;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Invokes a target method using standard reflection.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Rick Evans (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: ReflectiveMethodInvocation.cs,v 1.18 2008/02/06 18:28:52 bbaia Exp $</version>
[Serializable]
public class ReflectiveMethodInvocation : AbstractMethodInvocation
{
/// <summary>
/// The method invocation that is to be invoked on the proxy.
/// </summary>
protected MethodInfo proxyMethod;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation"/> class.
/// </summary>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">The target method proxied.</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If any of the <paramref name="target"/> or <paramref name="method"/>
/// parameters is <see langword="null"/>.
/// </exception>
public ReflectiveMethodInvocation(
object proxy, object target, MethodInfo method, MethodInfo proxyMethod,
object[] arguments, Type targetType, IList interceptors)
: base(proxy, target, method, arguments, targetType, interceptors)
{
this.proxyMethod = proxyMethod;
}
/// <summary>
/// Invokes the joinpoint using standard reflection.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/>
protected override object InvokeJoinpoint()
{
try
{
if (proxyMethod == null)
{
return method.Invoke(target, arguments);
}
else
{
return proxyMethod.Invoke(target, arguments);
}
}
catch (TargetInvocationException ex)
{
throw ReflectionUtils.UnwrapTargetInvocationException(ex);
}
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation"/> instance
/// from the specified <see cref="AopAlliance.Intercept.IMethodInvocation"/> and
/// increments the interceptor index.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
protected override IMethodInvocation PrepareMethodInvocationForProceed(IMethodInvocation invocation)
{
ReflectiveMethodInvocation rmi = new ReflectiveMethodInvocation(
this.proxy, this.target, this.method, this.proxyMethod, this.arguments, this.targetType, this.interceptors);
rmi.currentInterceptorIndex = this.currentInterceptorIndex + 1;
return rmi;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using Spring.Util;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Invokes a target method using standard reflection.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Rick Evans (.NET)</author>
/// <author>Bruno Baia (.NET)</author>
[Serializable]
public class ReflectiveMethodInvocation : AbstractMethodInvocation
{
/// <summary>
/// The method invocation that is to be invoked on the proxy.
/// </summary>
protected MethodInfo proxyMethod;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation"/> class.
/// </summary>
/// <param name="proxy">The AOP proxy.</param>
/// <param name="target">The target object.</param>
/// <param name="method">The target method proxied.</param>
/// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="arguments">The target method's arguments.</param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target object.</param>
/// <param name="interceptors">
/// The list of interceptors that are to be applied. May be
/// <cref lang="null"/>.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If any of the <paramref name="target"/> or <paramref name="method"/>
/// parameters is <see langword="null"/>.
/// </exception>
public ReflectiveMethodInvocation(
object proxy, object target, MethodInfo method, MethodInfo proxyMethod,
object[] arguments, Type targetType, IList interceptors)
: base(proxy, target, method, arguments, targetType, interceptors)
{
this.proxyMethod = proxyMethod;
}
/// <summary>
/// Invokes the joinpoint using standard reflection.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses can override this to use custom invocation.
/// </p>
/// </remarks>
/// <returns>
/// The return value of the invocation of the joinpoint.
/// </returns>
/// <exception cref="System.Exception">
/// If invoking the joinpoint resulted in an exception.
/// </exception>
/// <see cref="Spring.Aop.Framework.AbstractMethodInvocation.InvokeJoinpoint"/>
protected override object InvokeJoinpoint()
{
try
{
if (proxyMethod == null)
{
return method.Invoke(target, arguments);
}
else
{
return proxyMethod.Invoke(target, arguments);
}
}
catch (TargetInvocationException ex)
{
throw ReflectionUtils.UnwrapTargetInvocationException(ex);
}
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.Framework.ReflectiveMethodInvocation"/> instance
/// from the specified <see cref="AopAlliance.Intercept.IMethodInvocation"/> and
/// increments the interceptor index.
/// </summary>
/// <param name="invocation">
/// The current <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance.
/// </param>
/// <returns>
/// The new <see cref="AopAlliance.Intercept.IMethodInvocation"/> instance to use.
/// </returns>
protected override IMethodInvocation PrepareMethodInvocationForProceed(IMethodInvocation invocation)
{
ReflectiveMethodInvocation rmi = new ReflectiveMethodInvocation(
this.proxy, this.target, this.method, this.proxyMethod, this.arguments, this.targetType, this.interceptors);
rmi.currentInterceptorIndex = this.currentInterceptorIndex + 1;
return rmi;
}
}
}

View File

@@ -1,88 +1,87 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <remarks>
/// <p>
/// Because the target source is static, the target object can be cached
/// and simply returned as is.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: StaticTargetSourceWrapper.cs,v 1.3 2007/03/16 04:01:20 aseovic Exp $</version>
[Serializable]
public sealed class StaticTargetSourceWrapper : ITargetSourceWrapper
{
private object target;
/// <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>
/// Returns the target object that proxy methods will be delegated to.
/// </summary>
/// <returns>The target object.</returns>
public object GetTarget()
{
return this.target;
}
/// <summary>
/// Performs application-defined tasks associated with freeing,
/// releasing, or resetting unmanaged resources.
/// </summary>
/// <remarks>
/// <note type="implementnotes">
/// This is a no-op operation in this implementation.
/// </note>
/// </remarks>
public void Dispose()
{
// do nothing, this is static target source wrapper...
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Decorates a target source with the <see cref="System.IDisposable"/>
/// interface.
/// </summary>
/// <remarks>
/// <p>
/// Because the target source is static, the target object can be cached
/// and simply returned as is.
/// </p>
/// </remarks>
/// <author>Aleksandar Seovic</author>
[Serializable]
public sealed class StaticTargetSourceWrapper : ITargetSourceWrapper
{
private object target;
/// <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>
/// Returns the target object that proxy methods will be delegated to.
/// </summary>
/// <returns>The target object.</returns>
public object GetTarget()
{
return this.target;
}
/// <summary>
/// Performs application-defined tasks associated with freeing,
/// releasing, or resetting unmanaged resources.
/// </summary>
/// <remarks>
/// <note type="implementnotes">
/// This is a no-op operation in this implementation.
/// </note>
/// </remarks>
public void Dispose()
{
// do nothing, this is static target source wrapper...
}
}
}

View File

@@ -1,96 +1,95 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Base interface holding AOP advice and a filter determining the
/// applicability of the advice (such as a pointcut).
/// </summary>
/// <remarks>
/// <note>
/// This interface is not for use by Spring.NET users, but exists rather to
/// allow for commonality in the support for different types of advice
/// within the framework.
/// </note>
/// <p>
/// Spring.NET AOP is centered on <b>around advice</b> delivered via method
/// <b>interception</b>, compliant with the AOP Alliance interception API.
/// The <see cref="Spring.Aop.IAdvisor"/> interface allows support for
/// different types of advice, such as <b>before</b> and <b>after</b>
/// advice, which need not be implemented using interception.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// <version>$Id: IAdvisor.cs,v 1.7 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IAdvisor
{
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// An advisor that was creating a mixin would be a per instance
/// operation and would thus return <see langword="true"/>. If the
/// advisor is not per instance, it is shared with all instances of the
/// advised class obtained from the same Spring.NET IoC container.
/// </p>
/// <p>
/// Use <c>singleton</c> and <c>prototype</c> object definitions or
/// appropriate programmatic proxy creation to ensure that
/// <see cref="Spring.Aop.IAdvisor"/>s have the correct lifecycle model.
/// </p>
/// <note>
/// This method is not currently used by the framework.
/// </note>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
bool IsPerInstance { get; }
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
IAdvice Advice { get; }
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Base interface holding AOP advice and a filter determining the
/// applicability of the advice (such as a pointcut).
/// </summary>
/// <remarks>
/// <note>
/// This interface is not for use by Spring.NET users, but exists rather to
/// allow for commonality in the support for different types of advice
/// within the framework.
/// </note>
/// <p>
/// Spring.NET AOP is centered on <b>around advice</b> delivered via method
/// <b>interception</b>, compliant with the AOP Alliance interception API.
/// The <see cref="Spring.Aop.IAdvisor"/> interface allows support for
/// different types of advice, such as <b>before</b> and <b>after</b>
/// advice, which need not be implemented using interception.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
public interface IAdvisor
{
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// An advisor that was creating a mixin would be a per instance
/// operation and would thus return <see langword="true"/>. If the
/// advisor is not per instance, it is shared with all instances of the
/// advised class obtained from the same Spring.NET IoC container.
/// </p>
/// <p>
/// Use <c>singleton</c> and <c>prototype</c> object definitions or
/// appropriate programmatic proxy creation to ensure that
/// <see cref="Spring.Aop.IAdvisor"/>s have the correct lifecycle model.
/// </p>
/// <note>
/// This method is not currently used by the framework.
/// </note>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
bool IsPerInstance { get; }
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
IAdvice Advice { get; }
}
}

View File

@@ -1,47 +1,46 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// AOP Aspect abstraction, holding a list of <see cref="Spring.Aop.IAdvisor"/>s
/// </summary>
/// <seealso cref="IAdvisor"/>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IAdvisors.cs,v 1.1 2007/08/03 14:38:30 markpollack Exp $</version>
public interface IAdvisors
{
/// <summary>
/// Gets or sets a list of advisors.
/// </summary>
/// <value>
/// A list of advisors.
/// </value>
IList Advisors { get; set; }
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// AOP Aspect abstraction, holding a list of <see cref="Spring.Aop.IAdvisor"/>s
/// </summary>
/// <seealso cref="IAdvisor"/>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IAdvisors
{
/// <summary>
/// Gets or sets a list of advisors.
/// </summary>
/// <value>
/// A list of advisors.
/// </value>
IList Advisors { get; set; }
}
}

View File

@@ -1,78 +1,77 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Advice that executes after a method returns <b>successfully</b>.
/// </summary>
/// <remarks>
/// <p>
/// <i>After</i> returning advice is invoked only on a normal method
/// return, but <b>not</b> if an exception is thrown. Such advice can see
/// the return value of the advised method invocation, but cannot change it.
/// </p>
/// <p>
/// Possible uses for this type of advice would include performing access
/// control checks on the return value of an advised method invocation, the
/// ubiquitous logging of method invocation return values (useful during
/// development), etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// <version>$Id: IAfterReturningAdvice.cs,v 1.6 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IAfterReturningAdvice : IAdvice
{
/// <summary>
/// Executes after <paramref name="target"/> <paramref name="method"/>
/// returns <b>successfully</b>.
/// </summary>
/// <remarks>
/// <p>
/// Note that the supplied <paramref name="returnValue"/> <b>cannot</b>
/// be changed by this type of advice... use the around advice type
/// (<see cref="AopAlliance.Intercept.IMethodInterceptor"/>) if you
/// need to change the return value of an advised method invocation.
/// The data encapsulated by the supplied <paramref name="returnValue"/>
/// can of course be modified though.
/// </p>
/// </remarks>
/// <param name="returnValue">
/// The value returned by the <paramref name="target"/>.
/// </param>
/// <param name="method">The intecepted method.</param>
/// <param name="args">The intercepted method's arguments.</param>
/// <param name="target">The target object.</param>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor.Invoke"/>
void AfterReturning(object returnValue, MethodInfo method, object[] args, object target);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Advice that executes after a method returns <b>successfully</b>.
/// </summary>
/// <remarks>
/// <p>
/// <i>After</i> returning advice is invoked only on a normal method
/// return, but <b>not</b> if an exception is thrown. Such advice can see
/// the return value of the advised method invocation, but cannot change it.
/// </p>
/// <p>
/// Possible uses for this type of advice would include performing access
/// control checks on the return value of an advised method invocation, the
/// ubiquitous logging of method invocation return values (useful during
/// development), etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
public interface IAfterReturningAdvice : IAdvice
{
/// <summary>
/// Executes after <paramref name="target"/> <paramref name="method"/>
/// returns <b>successfully</b>.
/// </summary>
/// <remarks>
/// <p>
/// Note that the supplied <paramref name="returnValue"/> <b>cannot</b>
/// be changed by this type of advice... use the around advice type
/// (<see cref="AopAlliance.Intercept.IMethodInterceptor"/>) if you
/// need to change the return value of an advised method invocation.
/// The data encapsulated by the supplied <paramref name="returnValue"/>
/// can of course be modified though.
/// </p>
/// </remarks>
/// <param name="returnValue">
/// The value returned by the <paramref name="target"/>.
/// </param>
/// <param name="method">The intecepted method.</param>
/// <param name="args">The intercepted method's arguments.</param>
/// <param name="target">The target object.</param>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor.Invoke"/>
void AfterReturning(object returnValue, MethodInfo method, object[] args, object target);
}
}

View File

@@ -1,55 +1,54 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for all before advice.
/// </summary>
/// <remarks>
/// <p>
/// <i>Before</i> advice is advice that executes before a joinpoint, but
/// which does not have the ability to prevent execution flow proceeding to
/// the joinpoint (unless it throws an <see cref="System.Exception"/>).
/// </p>
/// <p>
/// Spring.NET only supports <i>method</i> before advice. Although this
/// is unlikely to change, this API is designed to allow <i>field</i>
/// before advice in future if desired.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// <version>$Id: IBeforeAdvice.cs,v 1.4 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IBeforeAdvice : IAdvice
{
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for all before advice.
/// </summary>
/// <remarks>
/// <p>
/// <i>Before</i> advice is advice that executes before a joinpoint, but
/// which does not have the ability to prevent execution flow proceeding to
/// the joinpoint (unless it throws an <see cref="System.Exception"/>).
/// </p>
/// <p>
/// Spring.NET only supports <i>method</i> before advice. Although this
/// is unlikely to change, this API is designed to allow <i>field</i>
/// before advice in future if desired.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
public interface IBeforeAdvice : IAdvice
{
}
}

View File

@@ -1,93 +1,92 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for advisors that perform one or more AOP
/// <b>introductions</b>.
/// </summary>
/// <remarks>
/// <p>
/// This interface cannot be implemented directly; subinterfaces must
/// provide the advice type implementing the introduction.
/// </p>
/// <p>
/// Introduction is the implementation of additional interfaces (not
/// implemented by a target) via AOP advice.
/// </p>
/// </remarks>
/// <seealso cref="Spring.Aop.IIntroductionInterceptor"/>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IIntroductionAdvisor.cs,v 1.8 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IIntroductionAdvisor : IAdvisor
{
/// <summary>
/// Returns the filter determining which target classes this
/// introduction should apply to.
/// </summary>
/// <remarks>
/// <p>
/// This is the <see cref="System.Type"/> part of a pointcut.
/// Be advised that method matching doesn't make sense in the context
/// of introductions.
/// </p>
/// </remarks>
/// <value>
/// The filter determining which target classes this introduction
/// should apply to.
/// </value>
ITypeFilter TypeFilter { get; }
/// <summary>
/// Gets the interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <value>
/// The interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </value>
Type[] Interfaces { get; }
/// <summary>
/// Can the advised interfaces be implemented by the introduction
/// advice?
/// </summary>
/// <remarks>
/// <p>
/// Invoked <b>before</b> adding an
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>.
/// </p>
/// </remarks>
/// <exception cref="System.ArgumentException">
/// If the advised interfaces cannot be implemented by the introduction
/// advice.
/// </exception>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor.Interfaces"/>
void ValidateInterfaces();
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for advisors that perform one or more AOP
/// <b>introductions</b>.
/// </summary>
/// <remarks>
/// <p>
/// This interface cannot be implemented directly; subinterfaces must
/// provide the advice type implementing the introduction.
/// </p>
/// <p>
/// Introduction is the implementation of additional interfaces (not
/// implemented by a target) via AOP advice.
/// </p>
/// </remarks>
/// <seealso cref="Spring.Aop.IIntroductionInterceptor"/>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IIntroductionAdvisor : IAdvisor
{
/// <summary>
/// Returns the filter determining which target classes this
/// introduction should apply to.
/// </summary>
/// <remarks>
/// <p>
/// This is the <see cref="System.Type"/> part of a pointcut.
/// Be advised that method matching doesn't make sense in the context
/// of introductions.
/// </p>
/// </remarks>
/// <value>
/// The filter determining which target classes this introduction
/// should apply to.
/// </value>
ITypeFilter TypeFilter { get; }
/// <summary>
/// Gets the interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <value>
/// The interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </value>
Type[] Interfaces { get; }
/// <summary>
/// Can the advised interfaces be implemented by the introduction
/// advice?
/// </summary>
/// <remarks>
/// <p>
/// Invoked <b>before</b> adding an
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>.
/// </p>
/// </remarks>
/// <exception cref="System.ArgumentException">
/// If the advised interfaces cannot be implemented by the introduction
/// advice.
/// </exception>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor.Interfaces"/>
void ValidateInterfaces();
}
}

View File

@@ -1,62 +1,61 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Subinterface of the AOP Alliance
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface that
/// allows additional interfaces to be implemented by the interceptor, and
/// available via a proxy using that interceptor.
/// </summary>
/// <remarks>
/// <p>
/// This is a fundamental AOP concept called <b>introduction</b>.
/// </p>
/// <p>
/// Introductions are often <b>mixins</b>, enabling the building of composite
/// objects that can achieve many of the goals of multiple inheritance.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IIntroductionInterceptor.cs,v 1.3 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IIntroductionInterceptor : IMethodInterceptor
{
/// <summary>
/// Does this <see cref="Spring.Aop.IIntroductionInterceptor"/>
/// implement the given interface?
/// </summary>
/// <param name="intf">The interface to check.</param>
/// <returns>
/// <see langword="true"/> if this
/// <see cref="Spring.Aop.IIntroductionInterceptor"/>
/// implements the given interface.
/// </returns>
bool ImplementsInterface(Type intf);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Subinterface of the AOP Alliance
/// <see cref="AopAlliance.Intercept.IMethodInterceptor"/> interface that
/// allows additional interfaces to be implemented by the interceptor, and
/// available via a proxy using that interceptor.
/// </summary>
/// <remarks>
/// <p>
/// This is a fundamental AOP concept called <b>introduction</b>.
/// </p>
/// <p>
/// Introductions are often <b>mixins</b>, enabling the building of composite
/// objects that can achieve many of the goals of multiple inheritance.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IIntroductionInterceptor : IMethodInterceptor
{
/// <summary>
/// Does this <see cref="Spring.Aop.IIntroductionInterceptor"/>
/// implement the given interface?
/// </summary>
/// <param name="intf">The interface to check.</param>
/// <returns>
/// <see langword="true"/> if this
/// <see cref="Spring.Aop.IIntroductionInterceptor"/>
/// implements the given interface.
/// </returns>
bool ImplementsInterface(Type intf);
}
}

View File

@@ -1,73 +1,72 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Advice executed before a method is invoked.
/// </summary>
/// <remarks>
/// <p>
/// Such advice cannot prevent the method call proceeding, short of
/// throwing an <see cref="System.Exception"/>.
/// </p>
/// <p>
/// The main advantage of <c>before</c> advice is that there is no
/// possibility of inadvertently failing to proceed down the interceptor
/// chain, since there is no need (and indeed means) to invoke the next
/// interceptor in the call chain.
/// </p>
/// <p>
/// Possible uses for this type of advice would include performing class
/// invariant checks prior to the actual method invocation, the ubiquitous
/// logging of method invocations (useful during development), etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// <version>$Id: IMethodBeforeAdvice.cs,v 1.6 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IMethodBeforeAdvice : IBeforeAdvice
{
/// <summary>
/// The callback before a given method is invoked.
/// </summary>
/// <param name="method">The method being invoked.</param>
/// <param name="args">The arguments to the method.</param>
/// <param name="target">
/// The target of the method invocation. May be <see langword="null"/>.
/// </param>
/// <exception cref="System.Exception">
/// Thrown when and if this object wishes to abort the call. Any
/// exception so thrown will be propagated to the caller.
/// </exception>
void Before(MethodInfo method, object[] args, object target);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Advice executed before a method is invoked.
/// </summary>
/// <remarks>
/// <p>
/// Such advice cannot prevent the method call proceeding, short of
/// throwing an <see cref="System.Exception"/>.
/// </p>
/// <p>
/// The main advantage of <c>before</c> advice is that there is no
/// possibility of inadvertently failing to proceed down the interceptor
/// chain, since there is no need (and indeed means) to invoke the next
/// interceptor in the call chain.
/// </p>
/// <p>
/// Possible uses for this type of advice would include performing class
/// invariant checks prior to the actual method invocation, the ubiquitous
/// logging of method invocations (useful during development), etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="Spring.Aop.IThrowsAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
public interface IMethodBeforeAdvice : IBeforeAdvice
{
/// <summary>
/// The callback before a given method is invoked.
/// </summary>
/// <param name="method">The method being invoked.</param>
/// <param name="args">The arguments to the method.</param>
/// <param name="target">
/// The target of the method invocation. May be <see langword="null"/>.
/// </param>
/// <exception cref="System.Exception">
/// Thrown when and if this object wishes to abort the call. Any
/// exception so thrown will be propagated to the caller.
/// </exception>
void Before(MethodInfo method, object[] args, object target);
}
}

View File

@@ -1,151 +1,150 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop
{
/// <summary>
/// That part of an <see cref="Spring.Aop.IPointcut"/> that checks whether a
/// target method is eligible for advice.
/// </summary>
/// <remarks>
/// <p>
/// An <see cref="Spring.Aop.IMethodMatcher"/> may be evaluated
/// <b>statically</b> or at runtime (<b>dynamically</b>). Static
/// matching involves only the method signature and (possibly) any
/// <see cref="System.Attribute"/>s that have been applied to a method.
/// Dynamic matching additionally takes into account the actual argument
/// values passed to a method invocation.
/// </p>
/// <p>
/// If the value of the <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/>
/// property of an implementation instance returns <see langword="false"/>,
/// evaluation can be performed statically, and the result will be the same
/// for all invocations of this method, whatever their arguments. This
/// means that if the value of the
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> is
/// <see langword="false"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will never be invoked for the lifetime of the
/// <see cref="Spring.Aop.IMethodMatcher"/>.
/// </p>
/// <p>
/// If an implementation returns <see langword="true"/> in its two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method, and the value of it's
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property is
/// <see langword="true"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will be invoked <i>immediately before each and every potential
/// execution of the related advice</i>, to decide whether the advice
/// should run. All previous advice, such as earlier interceptors in an
/// interceptor chain, will have run, so any state changes they have
/// produced in parameters or thread local storage, will be available at
/// the time of evaluation.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IMethodMatcher.cs,v 1.9 2006/04/09 07:18:36 markpollack Exp $</version>
/// <seealso cref="TrueMethodMatcher"/>
public interface IMethodMatcher
{
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <remarks>
/// <p>
/// If <see langword="true"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will be invoked if the two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method returns <see langword="true"/>.
/// </p>
/// <p>
/// Note that this property can be checked when an AOP proxy is created,
/// and implementations need not check the value of this property again
/// before each method invocation.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this
/// <see cref="Spring.Aop.IMethodMatcher"/> is dynamic.
/// </value>
bool IsRuntime { get; }
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// This is a static check. If this method invocation returns
/// <see langword="false"/>,or if the
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property is
/// <see langword="false"/>, then no runtime check will be made.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
bool Matches(MethodInfo method, Type targetType);
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// In order for this method to have even been invoked, the supplied
/// <paramref name="method"/> must have matched
/// statically. This method is invoked only if the two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method returns <see langword="true"/> for the supplied
/// <paramref name="method"/> and <paramref name="targetType"/>, and
/// if the <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property
/// is <see langword="true"/>.
/// </p>
/// <p>
/// Invoked immediately <b>before</b> any potential running of the
/// advice, and <b>after</b> any advice earlier in the advice chain has
/// run.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
bool Matches(MethodInfo method, Type targetType, object[] args);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop
{
/// <summary>
/// That part of an <see cref="Spring.Aop.IPointcut"/> that checks whether a
/// target method is eligible for advice.
/// </summary>
/// <remarks>
/// <p>
/// An <see cref="Spring.Aop.IMethodMatcher"/> may be evaluated
/// <b>statically</b> or at runtime (<b>dynamically</b>). Static
/// matching involves only the method signature and (possibly) any
/// <see cref="System.Attribute"/>s that have been applied to a method.
/// Dynamic matching additionally takes into account the actual argument
/// values passed to a method invocation.
/// </p>
/// <p>
/// If the value of the <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/>
/// property of an implementation instance returns <see langword="false"/>,
/// evaluation can be performed statically, and the result will be the same
/// for all invocations of this method, whatever their arguments. This
/// means that if the value of the
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> is
/// <see langword="false"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will never be invoked for the lifetime of the
/// <see cref="Spring.Aop.IMethodMatcher"/>.
/// </p>
/// <p>
/// If an implementation returns <see langword="true"/> in its two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method, and the value of it's
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property is
/// <see langword="true"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will be invoked <i>immediately before each and every potential
/// execution of the related advice</i>, to decide whether the advice
/// should run. All previous advice, such as earlier interceptors in an
/// interceptor chain, will have run, so any state changes they have
/// produced in parameters or thread local storage, will be available at
/// the time of evaluation.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="TrueMethodMatcher"/>
public interface IMethodMatcher
{
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <remarks>
/// <p>
/// If <see langword="true"/>, the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will be invoked if the two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method returns <see langword="true"/>.
/// </p>
/// <p>
/// Note that this property can be checked when an AOP proxy is created,
/// and implementations need not check the value of this property again
/// before each method invocation.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this
/// <see cref="Spring.Aop.IMethodMatcher"/> is dynamic.
/// </value>
bool IsRuntime { get; }
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// This is a static check. If this method invocation returns
/// <see langword="false"/>,or if the
/// <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property is
/// <see langword="false"/>, then no runtime check will be made.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
bool Matches(MethodInfo method, Type targetType);
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// In order for this method to have even been invoked, the supplied
/// <paramref name="method"/> must have matched
/// statically. This method is invoked only if the two argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
/// method returns <see langword="true"/> for the supplied
/// <paramref name="method"/> and <paramref name="targetType"/>, and
/// if the <see cref="Spring.Aop.IMethodMatcher.IsRuntime"/> property
/// is <see langword="true"/>.
/// </p>
/// <p>
/// Invoked immediately <b>before</b> any potential running of the
/// advice, and <b>after</b> any advice earlier in the advice chain has
/// run.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
bool Matches(MethodInfo method, Type targetType, object[] args);
}
}

View File

@@ -1,61 +1,60 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Spring.NET's core pointcut abstraction.
/// </summary>
/// <remarks>
/// <p>
/// A pointcut is composed of <see cref="Spring.Aop.ITypeFilter"/>s and
/// <see cref="Spring.Aop.IMethodMatcher"/>s. Both these basic terms and an
/// <see cref="Spring.Aop.IPointcut"/> itself can be combined to build up
/// sophisticated combinations.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: IPointcut.cs,v 1.9 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IPointcut
{
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
ITypeFilter TypeFilter { get; }
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
IMethodMatcher MethodMatcher { get; }
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Spring.NET's core pointcut abstraction.
/// </summary>
/// <remarks>
/// <p>
/// A pointcut is composed of <see cref="Spring.Aop.ITypeFilter"/>s and
/// <see cref="Spring.Aop.IMethodMatcher"/>s. Both these basic terms and an
/// <see cref="Spring.Aop.IPointcut"/> itself can be combined to build up
/// sophisticated combinations.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface IPointcut
{
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
ITypeFilter TypeFilter { get; }
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
IMethodMatcher MethodMatcher { get; }
}
}

View File

@@ -1,50 +1,49 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for all <see cref="Spring.Aop.IAdvisor"/>s that are
/// driven by a pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This covers nearly all advisors except introduction advisors, for which
/// method-level matching does not apply.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>
/// <version>$Id: IPointcutAdvisor.cs,v 1.3 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IPointcutAdvisor : IAdvisor
{
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
IPointcut Pointcut { get; }
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Superinterface for all <see cref="Spring.Aop.IAdvisor"/>s that are
/// driven by a pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This covers nearly all advisors except introduction advisors, for which
/// method-level matching does not apply.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>
public interface IPointcutAdvisor : IAdvisor
{
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
IPointcut Pointcut { get; }
}
}

View File

@@ -1,80 +1,79 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Used to obtain the current "target" of an AOP invocation
/// </summary>
/// <remarks>
/// <p>
/// This target will be invoked via reflection if no around advice chooses
/// to end the interceptor chain itself.
/// </p>
/// <p>
/// If an <see cref="Spring.Aop.ITargetSource"/> is <c>"static"</c>, it
/// will always return the same target, allowing optimizations in the AOP
/// framework. Dynamic target sources can support pooling, hot swapping etc.
/// </p>
/// <p>
/// Application developers don't usually need to work with target sources
/// directly: this is an AOP framework interface.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ITargetSource.cs,v 1.9 2007/10/10 18:07:38 markpollack Exp $</version>
public interface ITargetSource
{
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
Type TargetType { get; }
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
bool IsStatic { get; }
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
object GetTarget();
/// <summary>
/// Releases the target object.
/// </summary>
/// <param name="target">The target object to release.</param>
void ReleaseTarget(object target);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Used to obtain the current "target" of an AOP invocation
/// </summary>
/// <remarks>
/// <p>
/// This target will be invoked via reflection if no around advice chooses
/// to end the interceptor chain itself.
/// </p>
/// <p>
/// If an <see cref="Spring.Aop.ITargetSource"/> is <c>"static"</c>, it
/// will always return the same target, allowing optimizations in the AOP
/// framework. Dynamic target sources can support pooling, hot swapping etc.
/// </p>
/// <p>
/// Application developers don't usually need to work with target sources
/// directly: this is an AOP framework interface.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public interface ITargetSource
{
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
Type TargetType { get; }
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
bool IsStatic { get; }
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
object GetTarget();
/// <summary>
/// Releases the target object.
/// </summary>
/// <param name="target">The target object to release.</param>
void ReleaseTarget(object target);
}
}

View File

@@ -1,61 +1,60 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Simple marker interface for throws advice.
/// </summary>
/// <remarks>
/// <p>
/// There are no methods on this interface, as methods are discovered and
/// invoked via reflection. Please do see read the API documentation for the
/// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/> class;
/// said documention describes in detail the signature of the methods that
/// implementations of the <see cref="Spring.Aop.IThrowsAdvice"/> interface
/// must adhere to in the specific case of Spring.NET's implementation of
/// throws advice.
/// </p>
/// <p>
/// There are any number of possible uses for this type of advice. Some
/// examples would include the ubiquitous logging of any such exceptions,
/// monitoring the number and type of exceptions and sending emails to
/// a support desk once certain criteria have been met, wrapping generic
/// exceptions such as <see cref="System.Data.SqlClient.SqlException"/> in
/// exceptions that are more meaningful to your business logic, etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// <version>$Id: IThrowsAdvice.cs,v 1.5 2006/04/09 07:18:36 markpollack Exp $</version>
public interface IThrowsAdvice : IAdvice
{
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Simple marker interface for throws advice.
/// </summary>
/// <remarks>
/// <p>
/// There are no methods on this interface, as methods are discovered and
/// invoked via reflection. Please do see read the API documentation for the
/// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/> class;
/// said documention describes in detail the signature of the methods that
/// implementations of the <see cref="Spring.Aop.IThrowsAdvice"/> interface
/// must adhere to in the specific case of Spring.NET's implementation of
/// throws advice.
/// </p>
/// <p>
/// There are any number of possible uses for this type of advice. Some
/// examples would include the ubiquitous logging of any such exceptions,
/// monitoring the number and type of exceptions and sending emails to
/// a support desk once certain criteria have been met, wrapping generic
/// exceptions such as <see cref="System.Data.SqlClient.SqlException"/> in
/// exceptions that are more meaningful to your business logic, etc.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IMethodBeforeAdvice"/>
/// <seealso cref="Spring.Aop.IAfterReturningAdvice"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor"/>
public interface IThrowsAdvice : IAdvice
{
}
}

View File

@@ -1,59 +1,58 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// A filter that restricts the matching of a pointcut or introduction to
/// a given set of target types.
/// </summary>
/// <remarks>
/// <p>
/// Can be used as part of a pointcut, or for the entire targeting of an
/// introduction.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IPointcut"/>
/// <seealso cref="TrueTypeFilter.True"/>
/// <version>$Id: ITypeFilter.cs,v 1.2 2006/04/09 07:18:36 markpollack Exp $</version>
public interface ITypeFilter
{
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
bool Matches(Type type);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// A filter that restricts the matching of a pointcut or introduction to
/// a given set of target types.
/// </summary>
/// <remarks>
/// <p>
/// Can be used as part of a pointcut, or for the entire targeting of an
/// introduction.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <seealso cref="Spring.Aop.IPointcut"/>
/// <seealso cref="TrueTypeFilter.True"/>
public interface ITypeFilter
{
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
bool Matches(Type type);
}
}

View File

@@ -1,64 +1,63 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Aop;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract PointcutAdvisor that allows for any Advice to be configured.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: AbstractGenericPointcutAdvisor.cs,v 1.2 2007/08/10 17:39:44 bbaia Exp $</version>
[Serializable]
public abstract class AbstractGenericPointcutAdvisor : AbstractPointcutAdvisor
{
private IAdvice advice;
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public override IAdvice Advice
{
get { return this.advice; }
set { this.advice = value; }
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current
/// <see cref="System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> representation of this advisor.
/// </returns>
public override string ToString()
{
return GetType().Name + ": advice=[" + Advice + "]";
}
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Aop;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract PointcutAdvisor that allows for any Advice to be configured.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class AbstractGenericPointcutAdvisor : AbstractPointcutAdvisor
{
private IAdvice advice;
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public override IAdvice Advice
{
get { return this.advice; }
set { this.advice = value; }
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current
/// <see cref="System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> representation of this advisor.
/// </returns>
public override string ToString()
{
return GetType().Name + ": advice=[" + Advice + "]";
}
}
}

View File

@@ -1,137 +1,136 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using AopAlliance.Aop;
using Spring.Objects.Factory;
using Spring.Util;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract ObjectFactory-based IPointcutAdvisor that allows for any Advice to be
/// configured as reference to an Advice object in an ObjectFactory.
/// </summary>
/// <remarks>
/// specifying the name of an advice object instead of the advice object itself
/// (if running within an ObjectFactory/ApplicationContext increses loose coupling
/// at initialization time, in order not to initialize the advice object until the
/// pointcut actually matches.
/// </remarks>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack</author>
/// <version>$Id: AbstractObjectFactoryPointcutAdvisor.cs,v 1.2 2007/08/10 17:39:44 bbaia Exp $</version>
public abstract class AbstractObjectFactoryPointcutAdvisor : AbstractPointcutAdvisor, IObjectFactoryAware
{
private string adviceObjectName;
private IObjectFactory objectFactory;
private IAdvice advice;
private object adviceMonitor = new object();
/// <summary>
/// Gets or sets the name of the advice object that this advisor should refer to.
/// </summary>
/// <remarks>An instance of the specified object will be obtained on first access of
/// this advisor's advice. This advisor will only ever obtain at most one
/// single instance of the advice object, caching the instance for the lifetime of
/// the advisor.</remarks>
/// <value>The name of the advice object.</value>
public string AdviceObjectName
{
get { return adviceObjectName; }
set { adviceObjectName = value; }
}
#region IObjectFactoryAware Members
/// <summary>
/// Callback that supplies the owning factory to an object instance.
/// </summary>
/// <value>
/// Owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (may not be <see langword="null"/>). The object can immediately
/// call methods on the factory.
/// </value>
/// <remarks>
/// <p>
/// Invoked after population of normal object properties but before an init
/// callback like <see cref="Spring.Objects.Factory.IInitializingObject"/>'s
/// <see cref="Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
/// method or a custom init-method.
/// </p>
/// </remarks>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
public IObjectFactory ObjectFactory
{
set { objectFactory = value; }
}
#endregion
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public override IAdvice Advice
{
get
{
lock (adviceMonitor)
{
if (advice == null && adviceObjectName != null)
{
AssertUtils.State(objectFactory != null,
"ObjectFactory must be set to resolve 'adviceObjectName'");
advice = objectFactory.GetObject(adviceObjectName, typeof (IAdvice)) as IAdvice;
}
}
return advice;
}
set
{
advice = value;
}
}
/// <summary>
/// Describe this Advisor, showing name of advice object.
/// </summary>
/// <returns>
/// Type name and advice object name.
/// </returns>
public override string ToString()
{
return GetType().Name + ": advice object '" + AdviceObjectName + "'";
}
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using AopAlliance.Aop;
using Spring.Objects.Factory;
using Spring.Util;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract ObjectFactory-based IPointcutAdvisor that allows for any Advice to be
/// configured as reference to an Advice object in an ObjectFactory.
/// </summary>
/// <remarks>
/// specifying the name of an advice object instead of the advice object itself
/// (if running within an ObjectFactory/ApplicationContext increses loose coupling
/// at initialization time, in order not to initialize the advice object until the
/// pointcut actually matches.
/// </remarks>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack</author>
public abstract class AbstractObjectFactoryPointcutAdvisor : AbstractPointcutAdvisor, IObjectFactoryAware
{
private string adviceObjectName;
private IObjectFactory objectFactory;
private IAdvice advice;
private object adviceMonitor = new object();
/// <summary>
/// Gets or sets the name of the advice object that this advisor should refer to.
/// </summary>
/// <remarks>An instance of the specified object will be obtained on first access of
/// this advisor's advice. This advisor will only ever obtain at most one
/// single instance of the advice object, caching the instance for the lifetime of
/// the advisor.</remarks>
/// <value>The name of the advice object.</value>
public string AdviceObjectName
{
get { return adviceObjectName; }
set { adviceObjectName = value; }
}
#region IObjectFactoryAware Members
/// <summary>
/// Callback that supplies the owning factory to an object instance.
/// </summary>
/// <value>
/// Owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (may not be <see langword="null"/>). The object can immediately
/// call methods on the factory.
/// </value>
/// <remarks>
/// <p>
/// Invoked after population of normal object properties but before an init
/// callback like <see cref="Spring.Objects.Factory.IInitializingObject"/>'s
/// <see cref="Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
/// method or a custom init-method.
/// </p>
/// </remarks>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
public IObjectFactory ObjectFactory
{
set { objectFactory = value; }
}
#endregion
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public override IAdvice Advice
{
get
{
lock (adviceMonitor)
{
if (advice == null && adviceObjectName != null)
{
AssertUtils.State(objectFactory != null,
"ObjectFactory must be set to resolve 'adviceObjectName'");
advice = objectFactory.GetObject(adviceObjectName, typeof (IAdvice)) as IAdvice;
}
}
return advice;
}
set
{
advice = value;
}
}
/// <summary>
/// Describe this Advisor, showing name of advice object.
/// </summary>
/// <returns>
/// Type name and advice object name.
/// </returns>
public override string ToString()
{
return GetType().Name + ": advice object '" + AdviceObjectName + "'";
}
}
}

View File

@@ -1,166 +1,165 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Aop;
using Spring.Core;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract base class for <see cref="IPointcutAdvisor"/> implementations.
/// </summary>
/// <remarks>
/// Can be subclassed for returning a specific pointcut/advice or a freely configurable pointcut/advice.
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: AbstractPointcutAdvisor.cs,v 1.2 2008/01/14 20:49:47 oakinger Exp $</version>
[Serializable]
public abstract class AbstractPointcutAdvisor : IPointcutAdvisor, IOrdered
{
#region Fields
private int _order = Int32.MaxValue;
#endregion
#region IOrdered Members
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
#endregion
#region IAdvisor Members
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public abstract IAdvice Advice { get; set; }
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Not supported for dynamic advisors.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">Always.</exception>
/// <see cref="Spring.Aop.IAdvisor.IsPerInstance"/>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface " +
"is not yet supported in Spring.NET.");
}
}
#endregion
#region IPointcutAdvisor Members
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public abstract IPointcut Pointcut { get; set; }
#endregion
#region Methods
/// <summary>
/// Determines whether the specified <see cref="System.Object"/>
/// is equal to the current <see cref="System.Object"/>.
/// </summary>
/// <param name="o">The advisor to compare with.</param>
/// <returns>
/// <see langword="true"/> if this instance is equal to the
/// specified <see cref="System.Object"/>.
/// </returns>
public override bool Equals(object o)
{
if (!(o is AbstractPointcutAdvisor))
{
return false;
}
IPointcutAdvisor otherAdvisor = (IPointcutAdvisor)o;
if (otherAdvisor.Advice == null && otherAdvisor.Pointcut == null)
{
return (this.Advice == null && this.Pointcut == null);
}
else if (otherAdvisor.Advice == null)
{
return (Advice == null && otherAdvisor.Pointcut.Equals(this.Pointcut));
}
else if (otherAdvisor.Pointcut == null)
{
return (this.Pointcut == null && otherAdvisor.Advice.Equals(this.Advice));
}
else
{
return otherAdvisor.Advice.Equals(this.Advice) && otherAdvisor.Pointcut.Equals(this.Pointcut);
}
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for use
/// in hashing algorithms and data structures like a hash table.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return 0 // (SPRNET-847) base.GetHashCode()
+ 13 * (Pointcut == null ? 0 : Pointcut.GetHashCode())
+ 27 * (Advice == null ? 0 : Advice.GetHashCode());
}
#endregion
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using AopAlliance.Aop;
using Spring.Core;
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract base class for <see cref="IPointcutAdvisor"/> implementations.
/// </summary>
/// <remarks>
/// Can be subclassed for returning a specific pointcut/advice or a freely configurable pointcut/advice.
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class AbstractPointcutAdvisor : IPointcutAdvisor, IOrdered
{
#region Fields
private int _order = Int32.MaxValue;
#endregion
#region IOrdered Members
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
#endregion
#region IAdvisor Members
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <remarks>
/// <p>
/// An advice may be an interceptor, a throws advice, before advice,
/// introduction etc.
/// </p>
/// </remarks>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public abstract IAdvice Advice { get; set; }
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Not supported for dynamic advisors.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">Always.</exception>
/// <see cref="Spring.Aop.IAdvisor.IsPerInstance"/>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface " +
"is not yet supported in Spring.NET.");
}
}
#endregion
#region IPointcutAdvisor Members
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public abstract IPointcut Pointcut { get; set; }
#endregion
#region Methods
/// <summary>
/// Determines whether the specified <see cref="System.Object"/>
/// is equal to the current <see cref="System.Object"/>.
/// </summary>
/// <param name="o">The advisor to compare with.</param>
/// <returns>
/// <see langword="true"/> if this instance is equal to the
/// specified <see cref="System.Object"/>.
/// </returns>
public override bool Equals(object o)
{
if (!(o is AbstractPointcutAdvisor))
{
return false;
}
IPointcutAdvisor otherAdvisor = (IPointcutAdvisor)o;
if (otherAdvisor.Advice == null && otherAdvisor.Pointcut == null)
{
return (this.Advice == null && this.Pointcut == null);
}
else if (otherAdvisor.Advice == null)
{
return (Advice == null && otherAdvisor.Pointcut.Equals(this.Pointcut));
}
else if (otherAdvisor.Pointcut == null)
{
return (this.Pointcut == null && otherAdvisor.Advice.Equals(this.Advice));
}
else
{
return otherAdvisor.Advice.Equals(this.Advice) && otherAdvisor.Pointcut.Equals(this.Pointcut);
}
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for use
/// in hashing algorithms and data structures like a hash table.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return 0 // (SPRNET-847) base.GetHashCode()
+ 13 * (Pointcut == null ? 0 : Pointcut.GetHashCode())
+ 27 * (Advice == null ? 0 : Advice.GetHashCode());
}
#endregion
}
}

View File

@@ -1,275 +1,275 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security.Permissions;
using AopAlliance.Aop;
using Spring.Core;
using Spring.Objects;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract base regular expression pointcut object.
/// </summary>
/// <remarks>
/// <p>
/// The regular expressions must be a match. For example, the
/// <code>.*Get.*</code> pattern will match <c>Com.Mycom.Foo.GetBar()</c>, and
/// <code>Get.*</code> will not.
/// </p>
/// <p>
/// This base class is serializable. Subclasses should decorate all
/// fields with the <see cref="System.NonSerializedAttribute"/> - the
/// <see cref="AbstractRegularExpressionMethodPointcut.InitPatternRepresentation"/>
/// method in this class will be invoked again on the client side on deserialization.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public abstract class AbstractRegularExpressionMethodPointcut
: StaticMethodMatcherPointcut, ITypeFilter, ISerializable
{
[NonSerialized]
private object[] _patterns = ObjectUtils.EmptyObjects;
#region Constructors
/// <summary>
/// Creates a new instance of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected AbstractRegularExpressionMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the <see cref="AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
/// <exception cref="AopAlliance.Aop.AspectException">
/// If an error was encountered during the deserialization process.
/// </exception>
protected AbstractRegularExpressionMethodPointcut(
SerializationInfo info, StreamingContext context)
{
_patterns = (object[]) info.GetValue("Patterns", typeof(object[]));
try
{
InitPatternRepresentation(_patterns);
}
catch (Exception ex)
{
throw new AspectException(
"Failed to deserialize AOP regular expression pointcut: " + ex.Message);
}
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public override ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Convenience property for setting a single pattern.
/// </summary>
/// <remarks>
/// Use this property or Patterns, not both.
/// </remarks>
public virtual object Pattern
{
get { return (_patterns.Length > 0 ? _patterns[0] : null); }
set
{
AssertUtils.ArgumentNotNull(value, "Pattern");
this.Patterns = new object[] {value};
}
}
/// <summary>
/// The regular expressions defining methods to match.
/// </summary>
/// <remarks>
/// Matching will be the union of all these; if any match,
/// the pointcut matches.
/// </remarks>
public virtual object[] Patterns
{
get { return _patterns; }
set
{
AssertUtils.ArgumentNotNull(value, "Patterns");
this._patterns = value;
InitPatternRepresentation(this.Patterns);
}
}
#endregion
#region Methods
/// <summary>
/// Populates a <see cref="System.Runtime.Serialization.SerializationInfo"/> with
/// the data needed to serialize the target object.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate
/// with data.
/// </param>
/// <param name="context">
/// The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>)
/// for this serialization.
/// </param>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Patterns", _patterns);
}
/// <summary>
/// Subclasses must implement this to initialize regular expression pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Can be invoked multiple times.
/// </p>
/// <p>
/// This method will be invoked from the <see cref="Patterns"/> property,
/// and also on deserialization.
/// </p>
/// </remarks>
/// <param name="patterns">
/// The patterns to initialize.
/// </param>
/// <exception cref="System.ArgumentException">
/// In the case of an invalid pattern.
/// </exception>
protected abstract void InitPatternRepresentation(object[] patterns);
/// <summary>
/// Does the pattern at the supplied <paramref name="patternIndex"/>
/// match this <paramref name="pattern"/>?
/// </summary>
/// <param name="pattern">The pattern to match</param>
/// <param name="patternIndex">The index of pattern.</param>
/// <returns>
/// <see langword="true"/> if there is a match.
/// </returns>
protected abstract bool Matches(string pattern, int patternIndex);
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Try to match the regular expression against the fully qualified name
/// of the method's declaring <see cref="System.Type"/>, plus the name of
/// the supplied <paramref name="method"/>.
/// </p>
/// <p>
/// Note that the declaring <see cref="System.Type"/> is that
/// <see cref="System.Type"/> that originally declared
/// the method, not necessarily the <see cref="System.Type"/> that is
/// currently exposing it. For example, <see cref="System.Object.Equals(object)"/>
/// matches any subclass of <see cref="System.Object"/>'s
/// <see cref="System.Object.Equals(object)"/> method.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
string patt = method.DeclaringType.FullName + "." + method.Name;
for (int i = 0; i < this.Patterns.Length; ++i)
{
bool matched = Matches(patt, i);
if (matched)
{
return true;
}
}
return false;
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// In this instance, simply returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public bool Matches(Type type)
{
return true;
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security.Permissions;
using AopAlliance.Aop;
using Spring.Core;
using Spring.Objects;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Abstract base regular expression pointcut object.
/// </summary>
/// <remarks>
/// <p>
/// The regular expressions must be a match. For example, the
/// <code>.*Get.*</code> pattern will match <c>Com.Mycom.Foo.GetBar()</c>, and
/// <code>Get.*</code> will not.
/// </p>
/// <p>
/// This base class is serializable. Subclasses should decorate all
/// fields with the <see cref="System.NonSerializedAttribute"/> - the
/// <see cref="AbstractRegularExpressionMethodPointcut.InitPatternRepresentation"/>
/// method in this class will be invoked again on the client side on deserialization.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public abstract class AbstractRegularExpressionMethodPointcut
: StaticMethodMatcherPointcut, ITypeFilter, ISerializable
{
[NonSerialized]
private object[] _patterns = ObjectUtils.EmptyObjects;
#region Constructors
/// <summary>
/// Creates a new instance of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected AbstractRegularExpressionMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the <see cref="AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
/// <exception cref="AopAlliance.Aop.AspectException">
/// If an error was encountered during the deserialization process.
/// </exception>
protected AbstractRegularExpressionMethodPointcut(
SerializationInfo info, StreamingContext context)
{
_patterns = (object[]) info.GetValue("Patterns", typeof(object[]));
try
{
InitPatternRepresentation(_patterns);
}
catch (Exception ex)
{
throw new AspectException(
"Failed to deserialize AOP regular expression pointcut: " + ex.Message);
}
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public override ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Convenience property for setting a single pattern.
/// </summary>
/// <remarks>
/// Use this property or Patterns, not both.
/// </remarks>
public virtual object Pattern
{
get { return (_patterns.Length > 0 ? _patterns[0] : null); }
set
{
AssertUtils.ArgumentNotNull(value, "Pattern");
this.Patterns = new object[] {value};
}
}
/// <summary>
/// The regular expressions defining methods to match.
/// </summary>
/// <remarks>
/// Matching will be the union of all these; if any match,
/// the pointcut matches.
/// </remarks>
public virtual object[] Patterns
{
get { return _patterns; }
set
{
AssertUtils.ArgumentNotNull(value, "Patterns");
this._patterns = value;
InitPatternRepresentation(this.Patterns);
}
}
#endregion
#region Methods
/// <summary>
/// Populates a <see cref="System.Runtime.Serialization.SerializationInfo"/> with
/// the data needed to serialize the target object.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate
/// with data.
/// </param>
/// <param name="context">
/// The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>)
/// for this serialization.
/// </param>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Patterns", _patterns);
}
/// <summary>
/// Subclasses must implement this to initialize regular expression pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Can be invoked multiple times.
/// </p>
/// <p>
/// This method will be invoked from the <see cref="Patterns"/> property,
/// and also on deserialization.
/// </p>
/// </remarks>
/// <param name="patterns">
/// The patterns to initialize.
/// </param>
/// <exception cref="System.ArgumentException">
/// In the case of an invalid pattern.
/// </exception>
protected abstract void InitPatternRepresentation(object[] patterns);
/// <summary>
/// Does the pattern at the supplied <paramref name="patternIndex"/>
/// match this <paramref name="pattern"/>?
/// </summary>
/// <param name="pattern">The pattern to match</param>
/// <param name="patternIndex">The index of pattern.</param>
/// <returns>
/// <see langword="true"/> if there is a match.
/// </returns>
protected abstract bool Matches(string pattern, int patternIndex);
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Try to match the regular expression against the fully qualified name
/// of the method's declaring <see cref="System.Type"/>, plus the name of
/// the supplied <paramref name="method"/>.
/// </p>
/// <p>
/// Note that the declaring <see cref="System.Type"/> is that
/// <see cref="System.Type"/> that originally declared
/// the method, not necessarily the <see cref="System.Type"/> that is
/// currently exposing it. For example, <see cref="System.Object.Equals(object)"/>
/// matches any subclass of <see cref="System.Object"/>'s
/// <see cref="System.Object.Equals(object)"/> method.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
string patt = method.DeclaringType.FullName + "." + method.Name;
for (int i = 0; i < this.Patterns.Length; ++i)
{
bool matched = Matches(patt, i);
if (matched)
{
return true;
}
}
return false;
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// In this instance, simply returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public bool Matches(Type type)
{
return true;
}
#endregion
}
}

View File

@@ -1,204 +1,203 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// <see cref="Spring.Aop.IPointcut"/> implementation that matches methods
/// that have been decorated with a specified <see cref="System.Attribute"/>.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Ronald Wildenberg</author>
/// <version>$Id: AttributeMatchMethodPointcut.cs,v 1.8 2007/05/21 16:43:45 bbaia Exp $</version>
[Serializable]
public class AttributeMatchMethodPointcut : StaticMethodMatcherPointcut
{
private Type _attribute;
private bool _inherit = true;
private bool _checkInterfaces = false;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/> class.
/// </summary>
public AttributeMatchMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/> class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
public AttributeMatchMethodPointcut(Type attribute)
: this(attribute, true, false)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/>
/// class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
/// <param name="inherit">
/// Flag that controls whether or not the inheritance tree of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
public AttributeMatchMethodPointcut(Type attribute, bool inherit)
: this(attribute, inherit, false)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/>
/// class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
/// <param name="inherit">
/// Flag that controls whether or not the inheritance tree of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
/// <param name="checkInterfaces">
/// Flag that controls whether or not interfaces attributes of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
public AttributeMatchMethodPointcut(Type attribute, bool inherit, bool checkInterfaces)
{
Attribute = attribute;
Inherit = inherit;
CheckInterfaces = checkInterfaces;
}
/// <summary>
/// The <see cref="System.Attribute"/> to match.
/// </summary>
/// <exception cref="System.ArgumentException">
/// If the supplied value is not a <see cref="System.Type"/> that
/// derives from the <see cref="System.Attribute"/> class.
/// </exception>
public virtual Type Attribute
{
get { return _attribute; }
set
{
if (value != null)
{
if (!typeof (Attribute).IsAssignableFrom(value))
{
throw new ArgumentException(
string.Format(
"The [{0}] Type must be derived from the [System.Attribute] class.",
value));
}
}
_attribute = value;
}
}
/// <summary>
/// Is the inheritance tree of the method to be included in the search for the
/// <see cref="Attribute"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="true"/>.
/// </p>
/// </remarks>
public virtual bool Inherit
{
get { return _inherit; }
set { _inherit = value; }
}
/// <summary>
/// Is the interfaces attributes of the method to be included in the search for the
/// <see cref="Attribute"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="false"/>.
/// </p>
/// </remarks>
public virtual bool CheckInterfaces
{
get { return _checkInterfaces; }
set { _checkInterfaces = value; }
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
if (method.IsDefined(Attribute, Inherit))
{
// Checks whether the attribute is defined on the method or a super definition of the method
// but does not check attributes on implemented interfaces.
return true;
}
else
{
if (CheckInterfaces)
{
Type[] parameterTypes = ReflectionUtils.GetParameterTypes(method);
// Also check whether the attribute is defined on a method implemented from an interface.
// First find all interfaces for the type that contains the method.
// Next, check each interface for the presence of the attribute on the corresponding
// method from the interface.
foreach (Type interfaceType in method.DeclaringType.GetInterfaces())
{
MethodInfo intfMethod = interfaceType.GetMethod(method.Name, parameterTypes);
if (intfMethod != null && intfMethod.IsDefined(Attribute, Inherit))
{
return true;
}
}
}
return false;
}
}
}
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// <see cref="Spring.Aop.IPointcut"/> implementation that matches methods
/// that have been decorated with a specified <see cref="System.Attribute"/>.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <author>Ronald Wildenberg</author>
[Serializable]
public class AttributeMatchMethodPointcut : StaticMethodMatcherPointcut
{
private Type _attribute;
private bool _inherit = true;
private bool _checkInterfaces = false;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/> class.
/// </summary>
public AttributeMatchMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/> class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
public AttributeMatchMethodPointcut(Type attribute)
: this(attribute, true, false)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/>
/// class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
/// <param name="inherit">
/// Flag that controls whether or not the inheritance tree of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
public AttributeMatchMethodPointcut(Type attribute, bool inherit)
: this(attribute, inherit, false)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AttributeMatchMethodPointcut"/>
/// class.
/// </summary>
/// <param name="attribute">
/// The <see cref="System.Attribute"/> to match.
/// </param>
/// <param name="inherit">
/// Flag that controls whether or not the inheritance tree of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
/// <param name="checkInterfaces">
/// Flag that controls whether or not interfaces attributes of the
/// method to be included in the search for the <see cref="Attribute"/>?
/// </param>
public AttributeMatchMethodPointcut(Type attribute, bool inherit, bool checkInterfaces)
{
Attribute = attribute;
Inherit = inherit;
CheckInterfaces = checkInterfaces;
}
/// <summary>
/// The <see cref="System.Attribute"/> to match.
/// </summary>
/// <exception cref="System.ArgumentException">
/// If the supplied value is not a <see cref="System.Type"/> that
/// derives from the <see cref="System.Attribute"/> class.
/// </exception>
public virtual Type Attribute
{
get { return _attribute; }
set
{
if (value != null)
{
if (!typeof (Attribute).IsAssignableFrom(value))
{
throw new ArgumentException(
string.Format(
"The [{0}] Type must be derived from the [System.Attribute] class.",
value));
}
}
_attribute = value;
}
}
/// <summary>
/// Is the inheritance tree of the method to be included in the search for the
/// <see cref="Attribute"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="true"/>.
/// </p>
/// </remarks>
public virtual bool Inherit
{
get { return _inherit; }
set { _inherit = value; }
}
/// <summary>
/// Is the interfaces attributes of the method to be included in the search for the
/// <see cref="Attribute"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default is <see langword="false"/>.
/// </p>
/// </remarks>
public virtual bool CheckInterfaces
{
get { return _checkInterfaces; }
set { _checkInterfaces = value; }
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
if (method.IsDefined(Attribute, Inherit))
{
// Checks whether the attribute is defined on the method or a super definition of the method
// but does not check attributes on implemented interfaces.
return true;
}
else
{
if (CheckInterfaces)
{
Type[] parameterTypes = ReflectionUtils.GetParameterTypes(method);
// Also check whether the attribute is defined on a method implemented from an interface.
// First find all interfaces for the type that contains the method.
// Next, check each interface for the presence of the attribute on the corresponding
// method from the interface.
foreach (Type interfaceType in method.DeclaringType.GetInterfaces())
{
MethodInfo intfMethod = interfaceType.GetMethod(method.Name, parameterTypes);
if (intfMethod != null && intfMethod.IsDefined(Attribute, Inherit))
{
return true;
}
}
}
return false;
}
}
}
}

View File

@@ -1,118 +1,117 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for attribute-match method pointcuts that hold an Interceptor,
/// making them an Advisor.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: AttributeMatchMethodPointcutAdvisor.cs,v 1.3 2007/03/16 04:01:23 aseovic Exp $</version>
[Serializable]
public class AttributeMatchMethodPointcutAdvisor
: AttributeMatchMethodPointcut, IPointcutAdvisor, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="AttributeMatchMethodPointcutAdvisor"/> class.
/// </summary>
public AttributeMatchMethodPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="AttributeMatchMethodPointcutAdvisor"/> class
/// for the supplied <paramref name="advice"/>.
/// </summary>
/// <param name="advice"></param>
public AttributeMatchMethodPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">
/// Always; this property is not yet supported.
/// </exception>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface is " +
"not yet supported in Spring.NET.");
}
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public virtual IPointcut Pointcut
{
get { return this; }
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for attribute-match method pointcuts that hold an Interceptor,
/// making them an Advisor.
/// </summary>
/// <author>Bruno Baia</author>
[Serializable]
public class AttributeMatchMethodPointcutAdvisor
: AttributeMatchMethodPointcut, IPointcutAdvisor, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="AttributeMatchMethodPointcutAdvisor"/> class.
/// </summary>
public AttributeMatchMethodPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="AttributeMatchMethodPointcutAdvisor"/> class
/// for the supplied <paramref name="advice"/>.
/// </summary>
/// <param name="advice"></param>
public AttributeMatchMethodPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">
/// Always; this property is not yet supported.
/// </exception>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface is " +
"not yet supported in Spring.NET.");
}
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public virtual IPointcut Pointcut
{
get { return this; }
}
}
}

View File

@@ -1,176 +1,175 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for building up pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// All methods return a <see cref="Spring.Aop.Support.ComposablePointcut"/>
/// instance, which facilitates the following concise usage pattern...
/// </p>
/// <code language="C#">
/// IPointcut pointcut = new ComposablePointcut()
/// .Union(typeFilter)
/// .Intersection(methodMatcher)
/// .Intersection(pointcut);
/// </code>
/// <p>
/// There is no <c>Union()</c> method on this class. Use the
/// <see cref="Spring.Aop.Support.Pointcuts.Union"/> method for such functionality.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: ComposablePointcut.cs,v 1.7 2007/03/16 04:01:23 aseovic Exp $</version>
[Serializable]
public class ComposablePointcut : IPointcut
{
private ITypeFilter _typeFilter;
private IMethodMatcher _methodMatcher;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
/// that matches all the methods on all <see cref="System.Type"/>s.
/// </summary>
public ComposablePointcut()
{
_typeFilter = TrueTypeFilter.True;
_methodMatcher = TrueMethodMatcher.True;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
/// that uses the supplied <paramref name="typeFilter"/> and
/// <paramref name="methodMatcher"/>.
/// </summary>
/// <param name="typeFilter">
/// The type filter to use.
/// </param>
/// <param name="methodMatcher">
/// The method matcher to use.
/// </param>
public ComposablePointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
{
_typeFilter = typeFilter;
_methodMatcher = methodMatcher;
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return _typeFilter; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return _methodMatcher; }
}
/// <summary>
/// Changes the current type filter to be the union of the existing filter and the
/// supplied <paramref name="filter"/>.
/// </summary>
/// <param name="filter">The filter to union with.</param>
/// <returns>
/// The union of the existing filter and the supplied <paramref name="filter"/>.
/// </returns>
public virtual ComposablePointcut Union(ITypeFilter filter)
{
_typeFilter = TypeFilters.Union(_typeFilter, filter);
return this;
}
/// <summary>
/// Changes the current type filter to be the intersection of the existing filter
/// and the supplied <paramref name="filter"/>.
/// </summary>
/// <param name="filter">The filter to diff against.</param>
/// <returns>
/// The intersection of the existing filter and the supplied <paramref name="filter"/>.
/// </returns>
public virtual ComposablePointcut Intersection(ITypeFilter filter)
{
_typeFilter = TypeFilters.Intersection(_typeFilter, filter);
return this;
}
/// <summary>
/// Changes the current method matcher to be the union of the existing matcher and the
/// supplied <paramref name="matcher"/>.
/// </summary>
/// <param name="matcher">The matcher to union with.</param>
/// <returns>
/// The union of the existing matcher and the supplied <paramref name="matcher"/>.
/// </returns>
public virtual ComposablePointcut Union(IMethodMatcher matcher)
{
_methodMatcher = MethodMatchers.Union(_methodMatcher, matcher);
return this;
}
/// <summary>
/// Changes the current method matcher to be the intersection of the existing matcher
/// and the supplied <paramref name="matcher"/>.
/// </summary>
/// <param name="matcher">The matcher to diff against.</param>
/// <returns>
/// The intersection of the existing matcher and the supplied <paramref name="matcher"/>.
/// </returns>
public virtual ComposablePointcut Intersection(IMethodMatcher matcher)
{
_methodMatcher = MethodMatchers.Intersection(_methodMatcher, matcher);
return this;
}
/// <summary>
/// Changes current pointcut to intersection of the current and supplied pointcut
/// </summary>
/// <param name="other">pointcut to diff against</param>
/// <returns>updated pointcut</returns>
public virtual ComposablePointcut Intersection(IPointcut other)
{
_typeFilter = TypeFilters.Intersection(_typeFilter, other.TypeFilter);
_methodMatcher = MethodMatchers.Intersection(_methodMatcher, other.MethodMatcher);
return this;
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for building up pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// All methods return a <see cref="Spring.Aop.Support.ComposablePointcut"/>
/// instance, which facilitates the following concise usage pattern...
/// </p>
/// <code language="C#">
/// IPointcut pointcut = new ComposablePointcut()
/// .Union(typeFilter)
/// .Intersection(methodMatcher)
/// .Intersection(pointcut);
/// </code>
/// <p>
/// There is no <c>Union()</c> method on this class. Use the
/// <see cref="Spring.Aop.Support.Pointcuts.Union"/> method for such functionality.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class ComposablePointcut : IPointcut
{
private ITypeFilter _typeFilter;
private IMethodMatcher _methodMatcher;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
/// that matches all the methods on all <see cref="System.Type"/>s.
/// </summary>
public ComposablePointcut()
{
_typeFilter = TrueTypeFilter.True;
_methodMatcher = TrueMethodMatcher.True;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
/// that uses the supplied <paramref name="typeFilter"/> and
/// <paramref name="methodMatcher"/>.
/// </summary>
/// <param name="typeFilter">
/// The type filter to use.
/// </param>
/// <param name="methodMatcher">
/// The method matcher to use.
/// </param>
public ComposablePointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
{
_typeFilter = typeFilter;
_methodMatcher = methodMatcher;
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return _typeFilter; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return _methodMatcher; }
}
/// <summary>
/// Changes the current type filter to be the union of the existing filter and the
/// supplied <paramref name="filter"/>.
/// </summary>
/// <param name="filter">The filter to union with.</param>
/// <returns>
/// The union of the existing filter and the supplied <paramref name="filter"/>.
/// </returns>
public virtual ComposablePointcut Union(ITypeFilter filter)
{
_typeFilter = TypeFilters.Union(_typeFilter, filter);
return this;
}
/// <summary>
/// Changes the current type filter to be the intersection of the existing filter
/// and the supplied <paramref name="filter"/>.
/// </summary>
/// <param name="filter">The filter to diff against.</param>
/// <returns>
/// The intersection of the existing filter and the supplied <paramref name="filter"/>.
/// </returns>
public virtual ComposablePointcut Intersection(ITypeFilter filter)
{
_typeFilter = TypeFilters.Intersection(_typeFilter, filter);
return this;
}
/// <summary>
/// Changes the current method matcher to be the union of the existing matcher and the
/// supplied <paramref name="matcher"/>.
/// </summary>
/// <param name="matcher">The matcher to union with.</param>
/// <returns>
/// The union of the existing matcher and the supplied <paramref name="matcher"/>.
/// </returns>
public virtual ComposablePointcut Union(IMethodMatcher matcher)
{
_methodMatcher = MethodMatchers.Union(_methodMatcher, matcher);
return this;
}
/// <summary>
/// Changes the current method matcher to be the intersection of the existing matcher
/// and the supplied <paramref name="matcher"/>.
/// </summary>
/// <param name="matcher">The matcher to diff against.</param>
/// <returns>
/// The intersection of the existing matcher and the supplied <paramref name="matcher"/>.
/// </returns>
public virtual ComposablePointcut Intersection(IMethodMatcher matcher)
{
_methodMatcher = MethodMatchers.Intersection(_methodMatcher, matcher);
return this;
}
/// <summary>
/// Changes current pointcut to intersection of the current and supplied pointcut
/// </summary>
/// <param name="other">pointcut to diff against</param>
/// <returns>updated pointcut</returns>
public virtual ComposablePointcut Intersection(IPointcut other)
{
_typeFilter = TypeFilters.Intersection(_typeFilter, other.TypeFilter);
_methodMatcher = MethodMatchers.Intersection(_methodMatcher, other.MethodMatcher);
return this;
}
}
}

View File

@@ -1,244 +1,243 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Pointcut and method matcher for use in simple <b>cflow</b>-style
/// pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Evaluating such pointcuts is slower than evaluating normal pointcuts,
/// but can nevertheless be useful in some cases. Of course, your mileage
/// may vary as to what 'slower' actually means.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
/// <version>$Id: ControlFlowPointcut.cs,v 1.6 2006/04/09 07:18:37 markpollack Exp $</version>
[Serializable]
public class ControlFlowPointcut : IPointcut, ITypeFilter, IMethodMatcher
{
#region Fields
private Type _type;
private string _methodName;
private int _evaluationCount;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the <see cref="ControlFlowPointcut"/>
/// class.
/// </summary>
/// <param name="type">
/// The class under which <b>all</b> control flows are to be matched.
/// </param>
public ControlFlowPointcut(Type type) : this(type, null)
{
}
/// <summary>
/// Construct a new pointcut that matches all calls below the
/// given method in the given class.
/// </summary>
/// <remarks>
/// <p>
/// If the supplied <paramref name="methodName"/> is
/// <see langword="null"/>, <b>all</b> control flows below the given
/// class will be successfully matched.
/// </p>
/// </remarks>
/// <param name="type">
/// The class under which <b>all</b> control flows are to be matched.
/// </param>
/// <param name="methodName">
/// The method name under which <b>all</b> control flows are to be matched.
/// </param>
public ControlFlowPointcut(Type type, string methodName)
{
_type = type;
_methodName = methodName;
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Gets the number of times this pointcut has been <i>evaluated</i>.
/// </summary>
/// <remarks>
/// <p>
/// Useful as a debugging aid.
/// </p>
/// <p>
/// Note that this value is distinct from the number of times that this
/// pointcut sucessfully matches a target method, in that a
/// <see cref="ControlFlowPointcut"/> may be evaluated many times but
/// never actually match even once.
/// </p>
/// </remarks>
/// <value>
/// The number of times this pointcut has been <i>evaluated</i>.
/// </value>
public int EvaluationCount
{
get { return _evaluationCount; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public IMethodMatcher MethodMatcher
{
get { return this; }
}
/// <summary>
/// Is this a runtime pointcut?
/// </summary>
/// <remarks>
/// <p>
/// This implementation is a runtime pointcut, and so always returns
/// <see langword="true"/>.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this is a runtime pointcut.
/// </value>
/// <seealso cref="Spring.Aop.IMethodMatcher.IsRuntime"/>
public bool IsRuntime
{
get { return true; }
}
#endregion
#region Methods
/// <summary>
/// Should the pointcut apply to the supplied <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method for greater
/// filtering (and performance).
/// </p>
/// <p>
/// This, the default, implementation always matches (returns
/// <see langword="true"/>).
/// </p>
/// </remarks>
/// <param name="type">The candidate target class.</param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return true;
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// Perform static checking. If this returns false, or if the isRuntime() method
/// returns false, no runtime check will be made.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method if it is possible
/// to filter out some candidate classes.
/// </p>
/// <p>
/// This, the default, implementation always matches (returns
/// <see langword="true"/>). This means that the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will always be invoked.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target class (may be <see langword="null"/>, in which case the
/// candidate class must be taken to be the <paramref name="method"/>'s
/// declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
public virtual bool Matches(MethodInfo method, Type targetType)
{
return true;
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method if it is possible
/// to filter out some candidate classes.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">The target class.</param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
public virtual bool Matches(MethodInfo method, Type targetType, object[] args)
{
++_evaluationCount;
IControlFlow cflow = ControlFlowFactory.CreateControlFlow();
return (_methodName != null)
? cflow.Under(_type, _methodName)
: cflow.Under(_type);
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Pointcut and method matcher for use in simple <b>cflow</b>-style
/// pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Evaluating such pointcuts is slower than evaluating normal pointcuts,
/// but can nevertheless be useful in some cases. Of course, your mileage
/// may vary as to what 'slower' actually means.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public class ControlFlowPointcut : IPointcut, ITypeFilter, IMethodMatcher
{
#region Fields
private Type _type;
private string _methodName;
private int _evaluationCount;
#endregion
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the <see cref="ControlFlowPointcut"/>
/// class.
/// </summary>
/// <param name="type">
/// The class under which <b>all</b> control flows are to be matched.
/// </param>
public ControlFlowPointcut(Type type) : this(type, null)
{
}
/// <summary>
/// Construct a new pointcut that matches all calls below the
/// given method in the given class.
/// </summary>
/// <remarks>
/// <p>
/// If the supplied <paramref name="methodName"/> is
/// <see langword="null"/>, <b>all</b> control flows below the given
/// class will be successfully matched.
/// </p>
/// </remarks>
/// <param name="type">
/// The class under which <b>all</b> control flows are to be matched.
/// </param>
/// <param name="methodName">
/// The method name under which <b>all</b> control flows are to be matched.
/// </param>
public ControlFlowPointcut(Type type, string methodName)
{
_type = type;
_methodName = methodName;
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Gets the number of times this pointcut has been <i>evaluated</i>.
/// </summary>
/// <remarks>
/// <p>
/// Useful as a debugging aid.
/// </p>
/// <p>
/// Note that this value is distinct from the number of times that this
/// pointcut sucessfully matches a target method, in that a
/// <see cref="ControlFlowPointcut"/> may be evaluated many times but
/// never actually match even once.
/// </p>
/// </remarks>
/// <value>
/// The number of times this pointcut has been <i>evaluated</i>.
/// </value>
public int EvaluationCount
{
get { return _evaluationCount; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public IMethodMatcher MethodMatcher
{
get { return this; }
}
/// <summary>
/// Is this a runtime pointcut?
/// </summary>
/// <remarks>
/// <p>
/// This implementation is a runtime pointcut, and so always returns
/// <see langword="true"/>.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this is a runtime pointcut.
/// </value>
/// <seealso cref="Spring.Aop.IMethodMatcher.IsRuntime"/>
public bool IsRuntime
{
get { return true; }
}
#endregion
#region Methods
/// <summary>
/// Should the pointcut apply to the supplied <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method for greater
/// filtering (and performance).
/// </p>
/// <p>
/// This, the default, implementation always matches (returns
/// <see langword="true"/>).
/// </p>
/// </remarks>
/// <param name="type">The candidate target class.</param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return true;
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// Perform static checking. If this returns false, or if the isRuntime() method
/// returns false, no runtime check will be made.
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method if it is possible
/// to filter out some candidate classes.
/// </p>
/// <p>
/// This, the default, implementation always matches (returns
/// <see langword="true"/>). This means that the three argument
/// <see cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
/// method will always be invoked.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target class (may be <see langword="null"/>, in which case the
/// candidate class must be taken to be the <paramref name="method"/>'s
/// declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
public virtual bool Matches(MethodInfo method, Type targetType)
{
return true;
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Subclasses are encouraged to override this method if it is possible
/// to filter out some candidate classes.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">The target class.</param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type, object[])"/>
public virtual bool Matches(MethodInfo method, Type targetType, object[] args)
{
++_evaluationCount;
IControlFlow cflow = ControlFlowFactory.CreateControlFlow();
return (_methodName != null)
? cflow.Under(_type, _methodName)
: cflow.Under(_type);
}
#endregion
}
}

View File

@@ -1,241 +1,240 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Collections;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Simple <seealso cref="Spring.Aop.IIntroductionAdvisor"/> implementation that
/// by default applies to any class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DefaultIntroductionAdvisor.cs,v 1.11 2007/03/16 04:01:23 aseovic Exp $</version>
[Serializable]
public class DefaultIntroductionAdvisor : IIntroductionAdvisor, ITypeFilter
{
private IAdvice _introduction;
private ISet _interfaces = new HybridSet();
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <remarks>
/// <p>
/// This constructor adds all interfaces implemented by the supplied
/// <paramref name="introduction"/> (except the
/// <see cref="AopAlliance.Aop.IAdvice"/> interface) to the list of
/// interfaces to introduce.
/// </p>
/// </remarks>
/// <param name="introduction">The introduction to use.</param>
public DefaultIntroductionAdvisor(IAdvice introduction)
: this(introduction, introduction.GetType().GetInterfaces())
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <param name="introduction">The introduction to use.</param>
/// <param name="intf">
/// The interface to introduce.
/// </param>
public DefaultIntroductionAdvisor(IAdvice introduction, Type intf)
: this(introduction, new Type[] {intf})
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <param name="introduction">The introduction to use.</param>
/// <param name="interfaces">
/// The interfaces to introduce.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="introduction"/> is <see langword="null"/>.
/// </exception>
public DefaultIntroductionAdvisor(IAdvice introduction, Type[] interfaces)
{
if (introduction == null)
{
throw new ArgumentNullException("introduction", "Introduction cannot be null");
}
_introduction = introduction;
foreach (Type intf in interfaces)
{
if (intf != typeof (IAdvice))
{
AddInterface(intf);
}
}
}
/// <summary>
/// Returns the filter determining which target classes this
/// introduction should apply to.
/// </summary>
/// <value>
/// The filter determining which target classes this introduction
/// should apply to.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Gets the interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <value>
/// The interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </value>
public virtual Type[] Interfaces
{
get
{
Type[] interfaces = new Type[_interfaces.Count];
_interfaces.CopyTo(interfaces, 0);
return interfaces;
}
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Default for an introduction is per-instance interception.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
public virtual bool IsPerInstance
{
get { return true; }
}
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public virtual IAdvice Advice
{
get { return this._introduction; }
}
/// <summary>
/// Adds the supplied <paramref name="intf"/> to the list of
/// introduced interfaces.
/// </summary>
/// <param name="intf">The interface to add.</param>
/// <exception cref="System.ArgumentException">
/// If any of the <see cref="Interfaces"/> are not interface <see cref="System.Type"/>.
/// </exception>
public virtual void AddInterface(Type intf)
{
if(intf != null)
{
BailIfNotAnInterfaceType(intf);
_interfaces.Add(intf);
}
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// This, the default, implementation always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return true;
}
/// <summary>
/// Can the advised interfaces be implemented by the introduction
/// advice?
/// </summary>
/// <remarks>
/// <p>
/// Invoked <b>before</b> adding an
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>.
/// </p>
/// </remarks>
/// <exception cref="System.ArgumentException">
/// If the advised interfaces cannot be implemented by the introduction
/// advice.
/// </exception>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor.Interfaces"/>
/// <exception cref="System.ArgumentException">
/// If any of the <see cref="Interfaces"/> are not interface <see cref="System.Type"/>.
/// </exception>
public virtual void ValidateInterfaces()
{
foreach (Type intf in _interfaces)
{
BailIfNotAnInterfaceType(intf);
if (! intf.IsAssignableFrom(_introduction.GetType()))
{
throw new ArgumentException("Introduction [" + _introduction.GetType().FullName + "] " +
"does not implement interface '" + intf.FullName + "' specified in introduction advice.");
}
}
}
private static void BailIfNotAnInterfaceType(Type intf)
{
if (intf != null && !intf.IsInterface)
{
throw new ArgumentException("Type [" + intf.FullName + "] is not an interface; cannot be used in an introduction.");
}
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Collections;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Simple <seealso cref="Spring.Aop.IIntroductionAdvisor"/> implementation that
/// by default applies to any class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class DefaultIntroductionAdvisor : IIntroductionAdvisor, ITypeFilter
{
private IAdvice _introduction;
private ISet _interfaces = new HybridSet();
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <remarks>
/// <p>
/// This constructor adds all interfaces implemented by the supplied
/// <paramref name="introduction"/> (except the
/// <see cref="AopAlliance.Aop.IAdvice"/> interface) to the list of
/// interfaces to introduce.
/// </p>
/// </remarks>
/// <param name="introduction">The introduction to use.</param>
public DefaultIntroductionAdvisor(IAdvice introduction)
: this(introduction, introduction.GetType().GetInterfaces())
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <param name="introduction">The introduction to use.</param>
/// <param name="intf">
/// The interface to introduce.
/// </param>
public DefaultIntroductionAdvisor(IAdvice introduction, Type intf)
: this(introduction, new Type[] {intf})
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultIntroductionAdvisor"/> class using
/// the supplied <paramref name="introduction"/>
/// </summary>
/// <param name="introduction">The introduction to use.</param>
/// <param name="interfaces">
/// The interfaces to introduce.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="introduction"/> is <see langword="null"/>.
/// </exception>
public DefaultIntroductionAdvisor(IAdvice introduction, Type[] interfaces)
{
if (introduction == null)
{
throw new ArgumentNullException("introduction", "Introduction cannot be null");
}
_introduction = introduction;
foreach (Type intf in interfaces)
{
if (intf != typeof (IAdvice))
{
AddInterface(intf);
}
}
}
/// <summary>
/// Returns the filter determining which target classes this
/// introduction should apply to.
/// </summary>
/// <value>
/// The filter determining which target classes this introduction
/// should apply to.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return this; }
}
/// <summary>
/// Gets the interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <value>
/// The interfaces introduced by this
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </value>
public virtual Type[] Interfaces
{
get
{
Type[] interfaces = new Type[_interfaces.Count];
_interfaces.CopyTo(interfaces, 0);
return interfaces;
}
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Default for an introduction is per-instance interception.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
public virtual bool IsPerInstance
{
get { return true; }
}
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
public virtual IAdvice Advice
{
get { return this._introduction; }
}
/// <summary>
/// Adds the supplied <paramref name="intf"/> to the list of
/// introduced interfaces.
/// </summary>
/// <param name="intf">The interface to add.</param>
/// <exception cref="System.ArgumentException">
/// If any of the <see cref="Interfaces"/> are not interface <see cref="System.Type"/>.
/// </exception>
public virtual void AddInterface(Type intf)
{
if(intf != null)
{
BailIfNotAnInterfaceType(intf);
_interfaces.Add(intf);
}
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// This, the default, implementation always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return true;
}
/// <summary>
/// Can the advised interfaces be implemented by the introduction
/// advice?
/// </summary>
/// <remarks>
/// <p>
/// Invoked <b>before</b> adding an
/// <seealso cref="Spring.Aop.IIntroductionAdvisor"/>.
/// </p>
/// </remarks>
/// <exception cref="System.ArgumentException">
/// If the advised interfaces cannot be implemented by the introduction
/// advice.
/// </exception>
/// <seealso cref="Spring.Aop.IIntroductionAdvisor.Interfaces"/>
/// <exception cref="System.ArgumentException">
/// If any of the <see cref="Interfaces"/> are not interface <see cref="System.Type"/>.
/// </exception>
public virtual void ValidateInterfaces()
{
foreach (Type intf in _interfaces)
{
BailIfNotAnInterfaceType(intf);
if (! intf.IsAssignableFrom(_introduction.GetType()))
{
throw new ArgumentException("Introduction [" + _introduction.GetType().FullName + "] " +
"does not implement interface '" + intf.FullName + "' specified in introduction advice.");
}
}
}
private static void BailIfNotAnInterfaceType(Type intf)
{
if (intf != null && !intf.IsInterface)
{
throw new ArgumentException("Type [" + intf.FullName + "] is not an interface; cannot be used in an introduction.");
}
}
}
}

View File

@@ -1,60 +1,59 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Concrete ObjectFactory-based IPointcutAdvisor thta allows for any Advice to be
/// configured as reference to an Advice object in the ObjectFatory, as well as
/// the Pointcut to be configured through an object property.
/// </summary>
/// <remarks>
/// Specifying the name of an advice object instead of the advice object itself
/// (if running within a ObjectFactory/ApplicationContext) increases loose coupling
/// at initialization time, in order to not intialize the advice object until the pointcut
/// actually matches.
/// </remarks>
/// <author>Juerge Hoeller</author>
/// <author>Mark Pollack</author>
/// <version>$Id: DefaultObjectFactoryPointcutAdvisor.cs,v 1.1 2007/05/30 22:35:43 markpollack Exp $</version>
public class DefaultObjectFactoryPointcutAdvisor : AbstractObjectFactoryPointcutAdvisor
{
private IPointcut pointcut = TruePointcut.True;
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set { pointcut = (pointcut != null ? value : TruePointcut.True); }
}
/// <summary>
/// Describe this Advisor, showing pointcut and name of advice object.
/// </summary>
/// <returns>Type name , pointcut, and advice object name.</returns>
public override string ToString()
{
return GetType().Name + ": pointcut [" + Pointcut + "]; advice object = '" + AdviceObjectName + "'";
}
}
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Concrete ObjectFactory-based IPointcutAdvisor thta allows for any Advice to be
/// configured as reference to an Advice object in the ObjectFatory, as well as
/// the Pointcut to be configured through an object property.
/// </summary>
/// <remarks>
/// Specifying the name of an advice object instead of the advice object itself
/// (if running within a ObjectFactory/ApplicationContext) increases loose coupling
/// at initialization time, in order to not intialize the advice object until the pointcut
/// actually matches.
/// </remarks>
/// <author>Juerge Hoeller</author>
/// <author>Mark Pollack</author>
public class DefaultObjectFactoryPointcutAdvisor : AbstractObjectFactoryPointcutAdvisor
{
private IPointcut pointcut = TruePointcut.True;
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set { pointcut = (pointcut != null ? value : TruePointcut.True); }
}
/// <summary>
/// Describe this Advisor, showing pointcut and name of advice object.
/// </summary>
/// <returns>Type name , pointcut, and advice object name.</returns>
public override string ToString()
{
return GetType().Name + ": pointcut [" + Pointcut + "]; advice object = '" + AdviceObjectName + "'";
}
}
}

View File

@@ -1,111 +1,110 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient pointcut-driven advisor implementation.
/// </summary>
/// <remarks>
/// <p>
/// This is the most commonly used <see cref="Spring.Aop.IAdvisor"/> implementation.
/// It can be used with any pointcut and advice type, except for introductions.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DefaultPointcutAdvisor.cs,v 1.8 2007/05/30 22:35:43 markpollack Exp $</version>
[Serializable]
public class DefaultPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private IPointcut pointcut = TruePointcut.True;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> class.
/// </summary>
public DefaultPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>,
/// </summary>
/// <param name="advice">
/// The advice to use.
/// </param>
public DefaultPointcutAdvisor(IAdvice advice)
: this(TruePointcut.True, advice)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/> and
/// <paramref name="pointcut"/>.
/// </summary>
/// <param name="advice">
/// The advice to use.
/// </param>
/// <param name="pointcut">
/// The pointcut to use.
/// </param>
public DefaultPointcutAdvisor(IPointcut pointcut, IAdvice advice)
{
this.pointcut = pointcut;
Advice = advice;
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set { pointcut = value;}
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current
/// <see cref="System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> representation of this advisor.
/// </returns>
public override string ToString()
{
return GetType().Name + ": pointcut=[" + pointcut + "] advice=[" + Advice + "]";
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient pointcut-driven advisor implementation.
/// </summary>
/// <remarks>
/// <p>
/// This is the most commonly used <see cref="Spring.Aop.IAdvisor"/> implementation.
/// It can be used with any pointcut and advice type, except for introductions.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class DefaultPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private IPointcut pointcut = TruePointcut.True;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/> class.
/// </summary>
public DefaultPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>,
/// </summary>
/// <param name="advice">
/// The advice to use.
/// </param>
public DefaultPointcutAdvisor(IAdvice advice)
: this(TruePointcut.True, advice)
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/> and
/// <paramref name="pointcut"/>.
/// </summary>
/// <param name="advice">
/// The advice to use.
/// </param>
/// <param name="pointcut">
/// The pointcut to use.
/// </param>
public DefaultPointcutAdvisor(IPointcut pointcut, IAdvice advice)
{
this.pointcut = pointcut;
Advice = advice;
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set { pointcut = value;}
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents the current
/// <see cref="System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> representation of this advisor.
/// </returns>
public override string ToString()
{
return GetType().Name + ": pointcut=[" + pointcut + "] advice=[" + Advice + "]";
}
}
}

View File

@@ -1,114 +1,113 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient abstract superclass for dynamic method matchers that do
/// care about arguments at runtime.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DynamicMethodMatcher.cs,v 1.5 2006/04/09 07:18:37 markpollack Exp $</version>
public abstract class DynamicMethodMatcher : IMethodMatcher
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcher"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected DynamicMethodMatcher()
{
}
#endregion
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <value>
/// Always returns <see langword="true"/>, to specify that this is a
/// dynamic matcher.
/// </value>
public virtual bool IsRuntime
{
get { return true; }
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Derived classes can override this method to add preconditions for
/// dynamic matching.
/// </p>
/// <p>
/// This implementation always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public virtual bool Matches(MethodInfo method, Type targetType)
{
return true;
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Must be overriden by derived classes to provide criteria for dynamic matching.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
public abstract bool Matches(MethodInfo method, Type targetType, object[] args);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient abstract superclass for dynamic method matchers that do
/// care about arguments at runtime.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public abstract class DynamicMethodMatcher : IMethodMatcher
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcher"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected DynamicMethodMatcher()
{
}
#endregion
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <value>
/// Always returns <see langword="true"/>, to specify that this is a
/// dynamic matcher.
/// </value>
public virtual bool IsRuntime
{
get { return true; }
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Derived classes can override this method to add preconditions for
/// dynamic matching.
/// </p>
/// <p>
/// This implementation always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public virtual bool Matches(MethodInfo method, Type targetType)
{
return true;
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Must be overriden by derived classes to provide criteria for dynamic matching.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// <see langword="true"/> if there is a runtime match.</returns>
public abstract bool Matches(MethodInfo method, Type targetType, object[] args);
}
}

View File

@@ -1,176 +1,175 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass for <see cref="Spring.Aop.IAdvisor"/>s
/// that are also dynamic pointcuts.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DynamicMethodMatcherPointcutAdvisor.cs,v 1.6 2007/03/16 04:01:24 aseovic Exp $</version>
[Serializable]
public abstract class DynamicMethodMatcherPointcutAdvisor
: DynamicMethodMatcher, IPointcutAdvisor, IPointcut, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcherPointcutAdvisor"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected DynamicMethodMatcherPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcherPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
/// <param name="advice">
/// The advice portion of this advisor.
/// </param>
protected DynamicMethodMatcherPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Not supported for dynamic advisors.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">Always.</exception>
/// <see cref="Spring.Aop.IAdvisor.IsPerInstance"/>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface " +
"is not yet supported in Spring.NET.");
}
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns a filter that evaluates to <see langword="true"/>
/// for any <see cref="System.Type"/>.
/// </p>
/// </remarks>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return TrueTypeFilter.True; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns itself (this object).
/// </p>
/// </remarks>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return this; }
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns itself (this object).
/// </p>
/// </remarks>
public IPointcut Pointcut
{
get { return this; }
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass for <see cref="Spring.Aop.IAdvisor"/>s
/// that are also dynamic pointcuts.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public abstract class DynamicMethodMatcherPointcutAdvisor
: DynamicMethodMatcher, IPointcutAdvisor, IPointcut, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcherPointcutAdvisor"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected DynamicMethodMatcherPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.DynamicMethodMatcherPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
/// <param name="advice">
/// The advice portion of this advisor.
/// </param>
protected DynamicMethodMatcherPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <remarks>
/// <p>
/// Not supported for dynamic advisors.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">Always.</exception>
/// <see cref="Spring.Aop.IAdvisor.IsPerInstance"/>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface " +
"is not yet supported in Spring.NET.");
}
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns a filter that evaluates to <see langword="true"/>
/// for any <see cref="System.Type"/>.
/// </p>
/// </remarks>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return TrueTypeFilter.True; }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns itself (this object).
/// </p>
/// </remarks>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return this; }
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this aspect.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
/// <remarks>
/// <p>
/// This implementation always returns itself (this object).
/// </p>
/// </remarks>
public IPointcut Pointcut
{
get { return this; }
}
}
}

View File

@@ -1,181 +1,180 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Various utility methods relating to the composition of
/// <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// A method matcher may be evaluated statically (based on method and target
/// class) or need further evaluation dynamically (based on arguments at
/// the time of method invocation).
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: MethodMatchers.cs,v 1.7 2007/03/16 04:01:24 aseovic Exp $</version>
public sealed class MethodMatchers
{
/// <summary>
/// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// union of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// The newly created matcher will match all the methods that either of the two
/// supplied matchers would match.
/// </p>
/// </remarks>
/// <param name="firstMatcher">The first method matcher.</param>
/// <param name="secondMatcher">The second method matcher.</param>
/// <returns>
/// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// union of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
/// </returns>
public static IMethodMatcher Union(
IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
{
return new UnionMethodMatcher(firstMatcher, secondMatcher);
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// The newly created matcher will match only those methods that both
/// of the supplied matchers would match.
/// </p>
/// </remarks>
/// <param name="firstMatcher">The first method matcher.</param>
/// <param name="secondMatcher">The second method matcher.</param>
/// <returns>
/// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
/// </returns>
public static IMethodMatcher Intersection(
IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
{
return new IntersectionMethodMatcher(firstMatcher, secondMatcher);
}
#region Inner Class : UnionMethodMatcher
[Serializable]
private sealed class UnionMethodMatcher : IMethodMatcher
{
private IMethodMatcher a;
private IMethodMatcher b;
public UnionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
{
this.a = a;
this.b = b;
}
public bool IsRuntime
{
get { return a.IsRuntime || b.IsRuntime; }
}
public bool Matches(MethodInfo m, Type targetType)
{
return a.Matches(m, targetType) || b.Matches(m, targetType);
}
public bool Matches(MethodInfo m, Type targetType, object[] args)
{
return a.Matches(m, targetType, args) || b.Matches(m, targetType, args);
}
}
#endregion
#region Inner Class : IntersectionMethodMatcher
[Serializable]
private sealed class IntersectionMethodMatcher : IMethodMatcher
{
private IMethodMatcher a;
private IMethodMatcher b;
public IntersectionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
{
this.a = a;
this.b = b;
}
public bool IsRuntime
{
get { return a.IsRuntime || b.IsRuntime; }
}
public bool Matches(MethodInfo m, Type targetType)
{
return a.Matches(m, targetType) && b.Matches(m, targetType);
}
public bool Matches(MethodInfo m, Type targetType, object[] args)
{
// Because a dynamic intersection may be composed of a static and dynamic part,
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
// it will probably be an unsupported operation.
bool aMatches = a.IsRuntime ? a.Matches(m, targetType, args) : a.Matches(m, targetType);
bool bMatches = b.IsRuntime ? b.Matches(m, targetType, args) : b.Matches(m, targetType);
return aMatches && bMatches;
}
}
#endregion
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.MethodMatchers"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private MethodMatchers()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Various utility methods relating to the composition of
/// <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// A method matcher may be evaluated statically (based on method and target
/// class) or need further evaluation dynamically (based on arguments at
/// the time of method invocation).
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class MethodMatchers
{
/// <summary>
/// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// union of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// The newly created matcher will match all the methods that either of the two
/// supplied matchers would match.
/// </p>
/// </remarks>
/// <param name="firstMatcher">The first method matcher.</param>
/// <param name="secondMatcher">The second method matcher.</param>
/// <returns>
/// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// union of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
/// </returns>
public static IMethodMatcher Union(
IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
{
return new UnionMethodMatcher(firstMatcher, secondMatcher);
}
/// <summary>
/// Creates a new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s.
/// </summary>
/// <remarks>
/// <p>
/// The newly created matcher will match only those methods that both
/// of the supplied matchers would match.
/// </p>
/// </remarks>
/// <param name="firstMatcher">The first method matcher.</param>
/// <param name="secondMatcher">The second method matcher.</param>
/// <returns>
/// A new <see cref="Spring.Aop.IMethodMatcher"/> that is the
/// intersection of the two supplied <see cref="Spring.Aop.IMethodMatcher"/>s
/// </returns>
public static IMethodMatcher Intersection(
IMethodMatcher firstMatcher, IMethodMatcher secondMatcher)
{
return new IntersectionMethodMatcher(firstMatcher, secondMatcher);
}
#region Inner Class : UnionMethodMatcher
[Serializable]
private sealed class UnionMethodMatcher : IMethodMatcher
{
private IMethodMatcher a;
private IMethodMatcher b;
public UnionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
{
this.a = a;
this.b = b;
}
public bool IsRuntime
{
get { return a.IsRuntime || b.IsRuntime; }
}
public bool Matches(MethodInfo m, Type targetType)
{
return a.Matches(m, targetType) || b.Matches(m, targetType);
}
public bool Matches(MethodInfo m, Type targetType, object[] args)
{
return a.Matches(m, targetType, args) || b.Matches(m, targetType, args);
}
}
#endregion
#region Inner Class : IntersectionMethodMatcher
[Serializable]
private sealed class IntersectionMethodMatcher : IMethodMatcher
{
private IMethodMatcher a;
private IMethodMatcher b;
public IntersectionMethodMatcher(IMethodMatcher a, IMethodMatcher b)
{
this.a = a;
this.b = b;
}
public bool IsRuntime
{
get { return a.IsRuntime || b.IsRuntime; }
}
public bool Matches(MethodInfo m, Type targetType)
{
return a.Matches(m, targetType) && b.Matches(m, targetType);
}
public bool Matches(MethodInfo m, Type targetType, object[] args)
{
// Because a dynamic intersection may be composed of a static and dynamic part,
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
// it will probably be an unsupported operation.
bool aMatches = a.IsRuntime ? a.Matches(m, targetType, args) : a.Matches(m, targetType);
bool bMatches = b.IsRuntime ? b.Matches(m, targetType, args) : b.Matches(m, targetType);
return aMatches && bMatches;
}
}
#endregion
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.MethodMatchers"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private MethodMatchers()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,122 +1,121 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Pointcut object for simple method name matches, useful as an alternative to pure
/// regular expression based patterns.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: NameMatchMethodPointcut.cs,v 1.9 2007/03/16 04:01:24 aseovic Exp $</version>
[Serializable]
public class NameMatchMethodPointcut : StaticMethodMatcherPointcut
{
private string[] _mappedNames = new string[0];
/// <summary>
/// Convenience property when we have only a single method name
/// to match.
/// </summary>
/// <remarks>
/// <note type="caution">
/// Use either this property or the
/// <see cref="Spring.Aop.Support.NameMatchMethodPointcut.MappedNames"/> property,
/// not both.
/// </note>
/// </remarks>
public virtual string MappedName
{
set { MappedNames = new string[] {value}; }
}
/// <summary>
/// Set the method names defining methods to match.
/// </summary>
/// <remarks>
/// <p>
/// Matching will be the union of all these; if any match, the pointcut matches.
/// </p>
/// </remarks>
public virtual string[] MappedNames
{
set { this._mappedNames = value; }
}
/// <summary>
/// Does the <see cref="System.Reflection.MemberInfo.Name"/> of the supplied
/// <paramref name="method"/> matches any of the mapped names?
/// </summary>
/// <param name="method">
/// The <see cref="System.Reflection.MethodBase"/> to check.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target class.
/// </param>
/// <returns>
/// <see langword="true"/> if the name of the supplied
/// <paramref name="method"/> matches one of the mapped names.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
for (int i = 0; i < this._mappedNames.Length; i++)
{
string mappedName = this._mappedNames[i];
if (mappedName.Equals(method.Name) || IsMatch(method.Name, mappedName))
{
return true;
}
}
return false;
}
/// <summary>
/// Does the supplied <paramref name="methodName"/> match the supplied <paramref name="mappedName"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
/// as well as direct equality. Can be overridden in subclasses.
/// </p>
/// </remarks>
/// <param name="methodName">
/// The method name of the class.
/// </param>
/// <param name="mappedName">
/// The name in the descriptor.
/// </param>
/// <returns>
/// <b>True</b> if the names match.
/// </returns>
protected virtual bool IsMatch(string methodName, string mappedName)
{
return PatternMatchUtils.SimpleMatch(mappedName, methodName);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Pointcut object for simple method name matches, useful as an alternative to pure
/// regular expression based patterns.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class NameMatchMethodPointcut : StaticMethodMatcherPointcut
{
private string[] _mappedNames = new string[0];
/// <summary>
/// Convenience property when we have only a single method name
/// to match.
/// </summary>
/// <remarks>
/// <note type="caution">
/// Use either this property or the
/// <see cref="Spring.Aop.Support.NameMatchMethodPointcut.MappedNames"/> property,
/// not both.
/// </note>
/// </remarks>
public virtual string MappedName
{
set { MappedNames = new string[] {value}; }
}
/// <summary>
/// Set the method names defining methods to match.
/// </summary>
/// <remarks>
/// <p>
/// Matching will be the union of all these; if any match, the pointcut matches.
/// </p>
/// </remarks>
public virtual string[] MappedNames
{
set { this._mappedNames = value; }
}
/// <summary>
/// Does the <see cref="System.Reflection.MemberInfo.Name"/> of the supplied
/// <paramref name="method"/> matches any of the mapped names?
/// </summary>
/// <param name="method">
/// The <see cref="System.Reflection.MethodBase"/> to check.
/// </param>
/// <param name="targetType">
/// The <see cref="System.Type"/> of the target class.
/// </param>
/// <returns>
/// <see langword="true"/> if the name of the supplied
/// <paramref name="method"/> matches one of the mapped names.
/// </returns>
public override bool Matches(MethodInfo method, Type targetType)
{
for (int i = 0; i < this._mappedNames.Length; i++)
{
string mappedName = this._mappedNames[i];
if (mappedName.Equals(method.Name) || IsMatch(method.Name, mappedName))
{
return true;
}
}
return false;
}
/// <summary>
/// Does the supplied <paramref name="methodName"/> match the supplied <paramref name="mappedName"/>?
/// </summary>
/// <remarks>
/// <p>
/// The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
/// as well as direct equality. Can be overridden in subclasses.
/// </p>
/// </remarks>
/// <param name="methodName">
/// The method name of the class.
/// </param>
/// <param name="mappedName">
/// The name in the descriptor.
/// </param>
/// <returns>
/// <b>True</b> if the names match.
/// </returns>
protected virtual bool IsMatch(string methodName, string mappedName)
{
return PatternMatchUtils.SimpleMatch(mappedName, methodName);
}
}
}

View File

@@ -1,130 +1,129 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for name-match method pointcuts that hold an Interceptor,
/// making them an Advisor.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: NameMatchMethodPointcutAdvisor.cs,v 1.5 2007/05/30 22:35:43 markpollack Exp $</version>
[Serializable]
public class NameMatchMethodPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
#region Constructor(s)
/// <summary>
/// Creates a new instance of the
/// <see cref="NameMatchMethodPointcutAdvisor"/> class.
/// </summary>
public NameMatchMethodPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="NameMatchMethodPointcutAdvisor"/> class
/// for the supplied <paramref name="advice"/>.
/// </summary>
/// <param name="advice"></param>
public NameMatchMethodPointcutAdvisor(IAdvice advice)
{
Advice = advice;
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <remarks>Default is </remarks>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter {
set
{
pointcut.TypeFilter = value;
}
}
/// <summary>
/// Convenience property when we have only a single method name
/// to match.
/// </summary>
/// <remarks>
/// <note type="caution">
/// Use either this property or the
/// <see cref="Spring.Aop.Support.NameMatchMethodPointcut.MappedNames"/> property,
/// not both.
/// </note>
/// </remarks>
public string MappedName
{
set { pointcut.MappedName = value; }
}
/// <summary>
/// Set the method names defining methods to match.
/// </summary>
/// <remarks>
/// <p>
/// Matching will be the union of all these; if any match, the pointcut matches.
/// </p>
/// </remarks>
public string[] MappedNames
{
set { pointcut.MappedNames = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set
{
AssertUtils.AssertArgumentType(value, "pointcut", typeof(NameMatchMethodPointcut),
"Pointcut most be compatible with type NameMatchMethodPointcut");
pointcut = value as NameMatchMethodPointcut;
}
}
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for name-match method pointcuts that hold an Interceptor,
/// making them an Advisor.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public class NameMatchMethodPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
#region Constructor(s)
/// <summary>
/// Creates a new instance of the
/// <see cref="NameMatchMethodPointcutAdvisor"/> class.
/// </summary>
public NameMatchMethodPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="NameMatchMethodPointcutAdvisor"/> class
/// for the supplied <paramref name="advice"/>.
/// </summary>
/// <param name="advice"></param>
public NameMatchMethodPointcutAdvisor(IAdvice advice)
{
Advice = advice;
}
#endregion
#region Properties
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <remarks>Default is </remarks>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter {
set
{
pointcut.TypeFilter = value;
}
}
/// <summary>
/// Convenience property when we have only a single method name
/// to match.
/// </summary>
/// <remarks>
/// <note type="caution">
/// Use either this property or the
/// <see cref="Spring.Aop.Support.NameMatchMethodPointcut.MappedNames"/> property,
/// not both.
/// </note>
/// </remarks>
public string MappedName
{
set { pointcut.MappedName = value; }
}
/// <summary>
/// Set the method names defining methods to match.
/// </summary>
/// <remarks>
/// <p>
/// Matching will be the union of all these; if any match, the pointcut matches.
/// </p>
/// </remarks>
public string[] MappedNames
{
set { pointcut.MappedNames = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set
{
AssertUtils.AssertArgumentType(value, "pointcut", typeof(NameMatchMethodPointcut),
"Pointcut most be compatible with type NameMatchMethodPointcut");
pointcut = value as NameMatchMethodPointcut;
}
}
#endregion
}
}

View File

@@ -1,146 +1,145 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Various <see cref="Spring.Aop.IPointcut"/> related utility methods.
/// </summary>
/// <remarks>
/// <p>
/// These methods are particularly useful for composing pointcuts
/// using the union and intersection methods.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: Pointcuts.cs,v 1.6 2007/03/16 04:01:25 aseovic Exp $</version>
public sealed class Pointcuts
{
/// <summary>
/// Creates a union of the two supplied pointcuts.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// The union of the two supplied pointcuts.
/// </returns>
/// <seealso cref="Spring.Aop.Support.UnionPointcut"/>
public static IPointcut Union(IPointcut firstPointcut, IPointcut secondPointcut)
{
return new UnionPointcut(firstPointcut, secondPointcut);
}
/// <summary>
/// Creates an <see cref="Spring.Aop.IPointcut"/> that is the
/// intersection of the two supplied pointcuts.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// An <see cref="Spring.Aop.IPointcut"/> that is the
/// intersection of the two supplied pointcuts.
/// </returns>
public static IPointcut Intersection(IPointcut firstPointcut, IPointcut secondPointcut)
{
return new ComposablePointcut(
firstPointcut.TypeFilter, firstPointcut.MethodMatcher)
.Intersection(secondPointcut);
}
/// <summary>
/// Performs the least expensive check for a match.
/// </summary>
/// <param name="pointcut">
/// The <see cref="Spring.Aop.IPointcut"/> to be evaluated.
/// </param>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns><see langword="true"/> if there is a runtime match.</returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
public static bool Matches(
IPointcut pointcut, MethodInfo method, Type targetType, object[] args)
{
if(pointcut != null)
{
if (pointcut == TruePointcut.True)
{
return true;
}
if (pointcut.TypeFilter.Matches(targetType))
{
IMethodMatcher mm = pointcut.MethodMatcher;
if (mm.Matches(method, targetType))
{
return mm.IsRuntime ? mm.Matches(method, targetType, args) : true;
}
}
}
return false;
}
/// <summary>
/// Are the supplied <see cref="Spring.Aop.IPointcut"/>s equal?
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// <see langword="true"/> if the supplied <see cref="Spring.Aop.IPointcut"/>s
/// are equal.
/// </returns>
public static bool AreEqual(IPointcut firstPointcut, IPointcut secondPointcut)
{
return firstPointcut.TypeFilter == secondPointcut.TypeFilter
&& firstPointcut.MethodMatcher == secondPointcut.MethodMatcher;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.Pointcuts"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private Pointcuts()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Various <see cref="Spring.Aop.IPointcut"/> related utility methods.
/// </summary>
/// <remarks>
/// <p>
/// These methods are particularly useful for composing pointcuts
/// using the union and intersection methods.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
public sealed class Pointcuts
{
/// <summary>
/// Creates a union of the two supplied pointcuts.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// The union of the two supplied pointcuts.
/// </returns>
/// <seealso cref="Spring.Aop.Support.UnionPointcut"/>
public static IPointcut Union(IPointcut firstPointcut, IPointcut secondPointcut)
{
return new UnionPointcut(firstPointcut, secondPointcut);
}
/// <summary>
/// Creates an <see cref="Spring.Aop.IPointcut"/> that is the
/// intersection of the two supplied pointcuts.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// An <see cref="Spring.Aop.IPointcut"/> that is the
/// intersection of the two supplied pointcuts.
/// </returns>
public static IPointcut Intersection(IPointcut firstPointcut, IPointcut secondPointcut)
{
return new ComposablePointcut(
firstPointcut.TypeFilter, firstPointcut.MethodMatcher)
.Intersection(secondPointcut);
}
/// <summary>
/// Performs the least expensive check for a match.
/// </summary>
/// <param name="pointcut">
/// The <see cref="Spring.Aop.IPointcut"/> to be evaluated.
/// </param>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns><see langword="true"/> if there is a runtime match.</returns>
/// <seealso cref="Spring.Aop.IMethodMatcher.Matches(MethodInfo, Type)"/>
public static bool Matches(
IPointcut pointcut, MethodInfo method, Type targetType, object[] args)
{
if(pointcut != null)
{
if (pointcut == TruePointcut.True)
{
return true;
}
if (pointcut.TypeFilter.Matches(targetType))
{
IMethodMatcher mm = pointcut.MethodMatcher;
if (mm.Matches(method, targetType))
{
return mm.IsRuntime ? mm.Matches(method, targetType, args) : true;
}
}
}
return false;
}
/// <summary>
/// Are the supplied <see cref="Spring.Aop.IPointcut"/>s equal?
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
/// <returns>
/// <see langword="true"/> if the supplied <see cref="Spring.Aop.IPointcut"/>s
/// are equal.
/// </returns>
public static bool AreEqual(IPointcut firstPointcut, IPointcut secondPointcut)
{
return firstPointcut.TypeFilter == secondPointcut.TypeFilter
&& firstPointcut.MethodMatcher == secondPointcut.MethodMatcher;
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.Pointcuts"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
private Pointcuts()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,140 +1,140 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for regular expression method pointcuts that hold an
/// <see cref="AopAlliance.Aop.IAdvice"/>, making them an
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <remarks>
/// <p>
/// Configure this class using the <see cref="Pattern"/> and
/// <see cref="Patterns"/> pass-through properties. These are analogous
/// to the <see cref="AbstractRegularExpressionMethodPointcut.Pattern"/> and
/// <see cref="AbstractRegularExpressionMethodPointcut.Pattern"/>s properties of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/> class.
/// </p>
/// <p>
/// Can delegate to any type of regular expression pointcut. Currently only
/// pointcuts based on the regular expression classes from the .NET Base
/// Class Library are supported. The
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor.Pointcut"/>
/// property must be a subclass of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/> class.
/// </p>
/// <p>
/// This should not normally be set directly.
/// </p>
/// </remarks>
/// <author>Dmitriy Kopylenko</author>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
/// <see cref=" SdkRegularExpressionMethodPointcut"/>
[Serializable]
public class RegularExpressionMethodPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private AbstractRegularExpressionMethodPointcut pointcut;
#region Constructors
/// <summary>
/// Creates a new instance of the <see cref="RegularExpressionMethodPointcutAdvisor"/>
/// class.
/// </summary>
public RegularExpressionMethodPointcutAdvisor()
{
InitPointcut();
}
/// <summary>
/// Creates a new instance of the <see cref="RegularExpressionMethodPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>.
/// </summary><param name="advice">
/// The target advice.
/// </param>
public RegularExpressionMethodPointcutAdvisor(IAdvice advice)
{
Advice = advice;
InitPointcut();
}
#endregion
#region Properties
/// <summary>
/// A single pattern to be used during method evaluation.
/// </summary>
public string Pattern
{
set
{
AbstractRegularExpressionMethodPointcut armp = (AbstractRegularExpressionMethodPointcut) Pointcut;
armp.Pattern = value;
}
}
/// <summary>
/// Multiple patterns to be used during method evaluation.
/// </summary>
public string[] Patterns
{
set
{
AbstractRegularExpressionMethodPointcut armp = (AbstractRegularExpressionMethodPointcut) Pointcut;
armp.Patterns = value;
}
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set {
AssertUtils.AssertArgumentType(value, "pointcut", typeof(AbstractRegularExpressionMethodPointcut),
"Pointcut most be compatible with type AbstractRegularExpressionMethodPointuct");
pointcut = value as AbstractRegularExpressionMethodPointcut;
}
}
#endregion
/// <summary>
/// Initialises the pointcut.
/// </summary>
protected void InitPointcut()
{
pointcut = new SdkRegularExpressionMethodPointcut();
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient class for regular expression method pointcuts that hold an
/// <see cref="AopAlliance.Aop.IAdvice"/>, making them an
/// <see cref="Spring.Aop.IAdvisor"/>.
/// </summary>
/// <remarks>
/// <p>
/// Configure this class using the <see cref="Pattern"/> and
/// <see cref="Patterns"/> pass-through properties. These are analogous
/// to the <see cref="AbstractRegularExpressionMethodPointcut.Pattern"/> and
/// <see cref="AbstractRegularExpressionMethodPointcut.Pattern"/>s properties of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/> class.
/// </p>
/// <p>
/// Can delegate to any type of regular expression pointcut. Currently only
/// pointcuts based on the regular expression classes from the .NET Base
/// Class Library are supported. The
/// <see cref="Spring.Aop.Support.DefaultPointcutAdvisor.Pointcut"/>
/// property must be a subclass of the
/// <see cref="AbstractRegularExpressionMethodPointcut"/> class.
/// </p>
/// <p>
/// This should not normally be set directly.
/// </p>
/// </remarks>
/// <author>Dmitriy Kopylenko</author>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
/// <see cref=" SdkRegularExpressionMethodPointcut"/>
[Serializable]
public class RegularExpressionMethodPointcutAdvisor : AbstractGenericPointcutAdvisor
{
private AbstractRegularExpressionMethodPointcut pointcut;
#region Constructors
/// <summary>
/// Creates a new instance of the <see cref="RegularExpressionMethodPointcutAdvisor"/>
/// class.
/// </summary>
public RegularExpressionMethodPointcutAdvisor()
{
InitPointcut();
}
/// <summary>
/// Creates a new instance of the <see cref="RegularExpressionMethodPointcutAdvisor"/>
/// class for the supplied <paramref name="advice"/>.
/// </summary><param name="advice">
/// The target advice.
/// </param>
public RegularExpressionMethodPointcutAdvisor(IAdvice advice)
{
Advice = advice;
InitPointcut();
}
#endregion
#region Properties
/// <summary>
/// A single pattern to be used during method evaluation.
/// </summary>
public string Pattern
{
set
{
AbstractRegularExpressionMethodPointcut armp = (AbstractRegularExpressionMethodPointcut) Pointcut;
armp.Pattern = value;
}
}
/// <summary>
/// Multiple patterns to be used during method evaluation.
/// </summary>
public string[] Patterns
{
set
{
AbstractRegularExpressionMethodPointcut armp = (AbstractRegularExpressionMethodPointcut) Pointcut;
armp.Patterns = value;
}
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public override IPointcut Pointcut
{
get { return pointcut; }
set {
AssertUtils.AssertArgumentType(value, "pointcut", typeof(AbstractRegularExpressionMethodPointcut),
"Pointcut most be compatible with type AbstractRegularExpressionMethodPointuct");
pointcut = value as AbstractRegularExpressionMethodPointcut;
}
}
#endregion
/// <summary>
/// Initialises the pointcut.
/// </summary>
protected void InitPointcut()
{
pointcut = new SdkRegularExpressionMethodPointcut();
}
}
}

View File

@@ -1,80 +1,79 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Simple <see cref="Spring.Aop.ITypeFilter"/> implementation that matches
/// all classes classes (and any derived subclasses) of a give root
/// <see cref="System.Type"/>.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: RootTypeFilter.cs,v 1.3 2007/03/16 04:01:25 aseovic Exp $</version>
[Serializable]
public class RootTypeFilter : ITypeFilter
{
private Type _rootType;
/// <summary>
/// Creates a new instance of the
/// <see cref="RootTypeFilter"/> for the supplied
/// <paramref name="rootType"/>.
/// </summary>
/// <param name="rootType">The root <see cref="System.Type"/>.</param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="rootType"/> is <see langword="null"/>.
/// </exception>
public RootTypeFilter(Type rootType)
{
AssertUtils.ArgumentNotNull(rootType, "rootType");
_rootType = rootType;
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// Returns <see langword="true"/> if the supplied <paramref name="type"/>
/// can be assigned to the root <see cref="System.Type"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return _rootType.IsAssignableFrom(type);
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Simple <see cref="Spring.Aop.ITypeFilter"/> implementation that matches
/// all classes classes (and any derived subclasses) of a give root
/// <see cref="System.Type"/>.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public class RootTypeFilter : ITypeFilter
{
private Type _rootType;
/// <summary>
/// Creates a new instance of the
/// <see cref="RootTypeFilter"/> for the supplied
/// <paramref name="rootType"/>.
/// </summary>
/// <param name="rootType">The root <see cref="System.Type"/>.</param>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="rootType"/> is <see langword="null"/>.
/// </exception>
public RootTypeFilter(Type rootType)
{
AssertUtils.ArgumentNotNull(rootType, "rootType");
_rootType = rootType;
}
/// <summary>
/// Should the pointcut apply to the supplied
/// <see cref="System.Type"/>?
/// </summary>
/// <remarks>
/// <p>
/// Returns <see langword="true"/> if the supplied <paramref name="type"/>
/// can be assigned to the root <see cref="System.Type"/>.
/// </p>
/// </remarks>
/// <param name="type">
/// The candidate <see cref="System.Type"/>.
/// </param>
/// <returns>
/// <see langword="true"/> if the advice should apply to the supplied
/// <paramref name="type"/>
/// </returns>
public virtual bool Matches(Type type)
{
return _rootType.IsAssignableFrom(type);
}
}
}

View File

@@ -1,207 +1,207 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Common.Logging;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Regular expression based pointcut object.
/// </summary>
/// <remarks>
/// <p>
/// Uses the regular expression classes from the .NET Base Class Library.
/// </p>
/// <p>
/// The regular expressions must be a match. For example, the
/// <code>.*Get*</code> pattern will match <c>Com.Mycom.Foo.GetBar()</c>, and
/// <code>Get.*</code> will not.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public class SdkRegularExpressionMethodPointcut : AbstractRegularExpressionMethodPointcut
{
private ILog _logger = LogManager.GetLogger(typeof(SdkRegularExpressionMethodPointcut));
private Regex[] _compiledPatterns = new Regex[0];
private RegexOptions _defaultOptions = RegexOptions.None;
#region Constructors
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class.
/// </summary>
public SdkRegularExpressionMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class,
/// using the supplied pattern or <paramref name="patterns"/>.
/// </summary>
/// <param name="patterns">
/// The intial pattern value(s) to be matched against.
/// </param>
public SdkRegularExpressionMethodPointcut(params string[] patterns)
{
Patterns = patterns;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
/// <exception cref="AopAlliance.Aop.AspectException">
/// If an error was encountered during the deserialization process.
/// </exception>
protected SdkRegularExpressionMethodPointcut(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region Properties
/// <summary>
/// Gets or sets default options that should be used by
/// regular expressions that don't have options explicitly set.
/// </summary>
/// <value>
/// Default options that should be used by regular expressions
/// that don't have options explicitly set.
/// </value>
public RegexOptions DefaultOptions
{
get { return _defaultOptions; }
set
{
_defaultOptions = value;
InitPatternRepresentation(Patterns);
}
}
#endregion
#region Methods
/// <summary>
/// Initializes the regular expression pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Can be invoked multiple times.
/// </p>
/// <p>
/// This method will be invoked from the
/// <see cref="AbstractRegularExpressionMethodPointcut.Patterns"/> property,
/// and also on deserialization.
/// </p>
/// </remarks>
/// <param name="patterns">
/// The patterns to initialize.
/// </param>
/// <exception cref="System.ArgumentException">
/// In the case of an invalid pattern.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="patterns"/> is <see langword="null"/>.
/// </exception>
protected override void InitPatternRepresentation(object[] patterns)
{
AssertUtils.ArgumentNotNull(patterns, "patterns");
if (patterns.Length > 0)
{
_compiledPatterns = new Regex[patterns.Length];
for (int i = 0; i < patterns.Length; i++)
{
if (patterns[i] == null)
{
throw new ArgumentNullException(
"Null is not a valid value for an element of the Patterns property.");
}
else if (patterns[i] is Regex)
{
_compiledPatterns[i] = (Regex)patterns[i];
}
else if (patterns[i] is string)
{
_compiledPatterns[i] = new Regex((string)patterns[i], DefaultOptions);
}
else
{
throw new ArgumentException(
"You can only specify a string value or an instance of a Regex class " +
"as an element of the 'Patterns' property.");
}
}
}
}
/// <summary>
/// Does the pattern at the supplied <paramref name="patternIndex"/>
/// match this <paramref name="pattern"/>?
/// </summary>
/// <param name="pattern">The pattern to match</param>
/// <param name="patternIndex">The index of pattern.</param>
/// <returns>
/// <see langword="true"/> if there is a match.
/// </returns>
protected override bool Matches(string pattern, int patternIndex)
{
Match match = _compiledPatterns[patternIndex].Match(pattern);
bool matched = match.Success;
#region Instrumentation
if (_logger.IsDebugEnabled)
{
_logger.Debug("Candidate is: '" + pattern + "'; pattern is '" +
_compiledPatterns[patternIndex].ToString() + "'; matched=" + matched);
}
#endregion
return matched;
}
#endregion
}
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Common.Logging;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Regular expression based pointcut object.
/// </summary>
/// <remarks>
/// <p>
/// Uses the regular expression classes from the .NET Base Class Library.
/// </p>
/// <p>
/// The regular expressions must be a match. For example, the
/// <code>.*Get*</code> pattern will match <c>Com.Mycom.Foo.GetBar()</c>, and
/// <code>Get.*</code> will not.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public class SdkRegularExpressionMethodPointcut : AbstractRegularExpressionMethodPointcut
{
private ILog _logger = LogManager.GetLogger(typeof(SdkRegularExpressionMethodPointcut));
private Regex[] _compiledPatterns = new Regex[0];
private RegexOptions _defaultOptions = RegexOptions.None;
#region Constructors
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class.
/// </summary>
public SdkRegularExpressionMethodPointcut()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class,
/// using the supplied pattern or <paramref name="patterns"/>.
/// </summary>
/// <param name="patterns">
/// The intial pattern value(s) to be matched against.
/// </param>
public SdkRegularExpressionMethodPointcut(params string[] patterns)
{
Patterns = patterns;
}
/// <summary>
/// Creates a new instance of the
/// <see cref="SdkRegularExpressionMethodPointcut"/> class.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
/// that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
/// that contains contextual information about the source or destination.
/// </param>
/// <exception cref="AopAlliance.Aop.AspectException">
/// If an error was encountered during the deserialization process.
/// </exception>
protected SdkRegularExpressionMethodPointcut(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endregion
#region Properties
/// <summary>
/// Gets or sets default options that should be used by
/// regular expressions that don't have options explicitly set.
/// </summary>
/// <value>
/// Default options that should be used by regular expressions
/// that don't have options explicitly set.
/// </value>
public RegexOptions DefaultOptions
{
get { return _defaultOptions; }
set
{
_defaultOptions = value;
InitPatternRepresentation(Patterns);
}
}
#endregion
#region Methods
/// <summary>
/// Initializes the regular expression pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// Can be invoked multiple times.
/// </p>
/// <p>
/// This method will be invoked from the
/// <see cref="AbstractRegularExpressionMethodPointcut.Patterns"/> property,
/// and also on deserialization.
/// </p>
/// </remarks>
/// <param name="patterns">
/// The patterns to initialize.
/// </param>
/// <exception cref="System.ArgumentException">
/// In the case of an invalid pattern.
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// If the supplied <paramref name="patterns"/> is <see langword="null"/>.
/// </exception>
protected override void InitPatternRepresentation(object[] patterns)
{
AssertUtils.ArgumentNotNull(patterns, "patterns");
if (patterns.Length > 0)
{
_compiledPatterns = new Regex[patterns.Length];
for (int i = 0; i < patterns.Length; i++)
{
if (patterns[i] == null)
{
throw new ArgumentNullException(
"Null is not a valid value for an element of the Patterns property.");
}
else if (patterns[i] is Regex)
{
_compiledPatterns[i] = (Regex)patterns[i];
}
else if (patterns[i] is string)
{
_compiledPatterns[i] = new Regex((string)patterns[i], DefaultOptions);
}
else
{
throw new ArgumentException(
"You can only specify a string value or an instance of a Regex class " +
"as an element of the 'Patterns' property.");
}
}
}
}
/// <summary>
/// Does the pattern at the supplied <paramref name="patternIndex"/>
/// match this <paramref name="pattern"/>?
/// </summary>
/// <param name="pattern">The pattern to match</param>
/// <param name="patternIndex">The index of pattern.</param>
/// <returns>
/// <see langword="true"/> if there is a match.
/// </returns>
protected override bool Matches(string pattern, int patternIndex)
{
Match match = _compiledPatterns[patternIndex].Match(pattern);
bool matched = match.Success;
#region Instrumentation
if (_logger.IsDebugEnabled)
{
_logger.Debug("Candidate is: '" + pattern + "'; pattern is '" +
_compiledPatterns[patternIndex].ToString() + "'; matched=" + matched);
}
#endregion
return matched;
}
#endregion
}
}

View File

@@ -1,103 +1,102 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient abstract superclass for static method matchers that don't care
/// about arguments at runtime.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: StaticMethodMatcher.cs,v 1.6 2006/04/09 07:18:37 markpollack Exp $</version>
[Serializable]
public abstract class StaticMethodMatcher : IMethodMatcher
{
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <remarks>
/// <p>
/// Always returns <see langword="false"/>.
/// </p>
/// </remarks>
/// <value>
/// Always returns <see langword="false"/>.
/// </value>
public bool IsRuntime
{
get { return false; }
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Always throws a <see cref="System.NotSupportedException"/>. This
/// method should never be called on a static matcher.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// Always throws a <see cref="System.NotSupportedException"/>.
/// </returns>
/// <exception cref="System.NotSupportedException">
/// Always.
/// </exception>
public bool Matches(MethodInfo method, Type targetType, object[] args)
{
throw new NotSupportedException(
"Illegal IMethodMatcher usage. Cannot call 3-arg Matches method on a static matcher.");
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Must be implemented by a derived class in order to specify matching
/// rules.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public abstract bool Matches(MethodInfo method, Type targetType);
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient abstract superclass for static method matchers that don't care
/// about arguments at runtime.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public abstract class StaticMethodMatcher : IMethodMatcher
{
/// <summary>
/// Is this <see cref="Spring.Aop.IMethodMatcher"/> dynamic?
/// </summary>
/// <remarks>
/// <p>
/// Always returns <see langword="false"/>.
/// </p>
/// </remarks>
/// <value>
/// Always returns <see langword="false"/>.
/// </value>
public bool IsRuntime
{
get { return false; }
}
/// <summary>
/// Is there a runtime (dynamic) match for the supplied
/// <paramref name="method"/>?
/// </summary>
/// <remarks>
/// <p>
/// Always throws a <see cref="System.NotSupportedException"/>. This
/// method should never be called on a static matcher.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/>.
/// </param>
/// <param name="args">The arguments to the method</param>
/// <returns>
/// Always throws a <see cref="System.NotSupportedException"/>.
/// </returns>
/// <exception cref="System.NotSupportedException">
/// Always.
/// </exception>
public bool Matches(MethodInfo method, Type targetType, object[] args)
{
throw new NotSupportedException(
"Illegal IMethodMatcher usage. Cannot call 3-arg Matches method on a static matcher.");
}
/// <summary>
/// Does the supplied <paramref name="method"/> satisfy this matcher?
/// </summary>
/// <remarks>
/// <p>
/// Must be implemented by a derived class in order to specify matching
/// rules.
/// </p>
/// </remarks>
/// <param name="method">The candidate method.</param>
/// <param name="targetType">
/// The target <see cref="System.Type"/> (may be <see langword="null"/>,
/// in which case the candidate <see cref="System.Type"/> must be taken
/// to be the <paramref name="method"/>'s declaring class).
/// </param>
/// <returns>
/// <see langword="true"/> if this this method matches statically.
/// </returns>
public abstract bool Matches(MethodInfo method, Type targetType);
}
}

View File

@@ -1,85 +1,84 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Reflection;
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass when one wants to force subclasses to
/// implement the <see cref="Spring.Aop.IMethodMatcher"/> interface
/// but subclasses will still want to be pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="Spring.Aop.Support.StaticMethodMatcherPointcut.TypeFilter"/>
/// property can be overriden to customize <see cref="System.Type"/> filter
/// behavior as well.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: StaticMethodMatcherPointcut.cs,v 1.8 2007/05/30 22:35:43 markpollack Exp $</version>
[Serializable]
public abstract class StaticMethodMatcherPointcut : StaticMethodMatcher, IPointcut
{
private ITypeFilter typeFilter = TrueTypeFilter.True;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected StaticMethodMatcherPointcut()
{
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return typeFilter; }
set { typeFilter = value;}
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return this; }
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
using System;
using System.Reflection;
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass when one wants to force subclasses to
/// implement the <see cref="Spring.Aop.IMethodMatcher"/> interface
/// but subclasses will still want to be pointcuts.
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="Spring.Aop.Support.StaticMethodMatcherPointcut.TypeFilter"/>
/// property can be overriden to customize <see cref="System.Type"/> filter
/// behavior as well.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <author>Mark Pollack (.NET)</author>
[Serializable]
public abstract class StaticMethodMatcherPointcut : StaticMethodMatcher, IPointcut
{
private ITypeFilter typeFilter = TrueTypeFilter.True;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AbstractRegularExpressionMethodPointcut"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected StaticMethodMatcherPointcut()
{
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public virtual ITypeFilter TypeFilter
{
get { return typeFilter; }
set { typeFilter = value;}
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public virtual IMethodMatcher MethodMatcher
{
get { return this; }
}
}
}

View File

@@ -1,134 +1,133 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass for <see cref="Spring.Aop.IAdvisor"/>s that
/// are also static pointcuts.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
/// <version>$Id: StaticMethodMatcherPointcutAdvisor.cs,v 1.6 2006/04/09 07:18:37 markpollack Exp $</version>
[Serializable]
public abstract class StaticMethodMatcherPointcutAdvisor
: StaticMethodMatcherPointcut, IPointcutAdvisor, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.StaticMethodMatcherPointcutAdvisor"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected StaticMethodMatcherPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AbstractRegularExpressionMethodPointcut"/>
/// class for the supplied <paramref name="advice"/>
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
/// <param name="advice">
/// The advice to use.
/// </param>
public StaticMethodMatcherPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">
/// Always; this property is not yet supported.
/// </exception>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface is " +
"not yet supported in Spring.NET.");
}
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public virtual IPointcut Pointcut
{
get { return this; }
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Core;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Convenient superclass for <see cref="Spring.Aop.IAdvisor"/>s that
/// are also static pointcuts.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
[Serializable]
public abstract class StaticMethodMatcherPointcutAdvisor
: StaticMethodMatcherPointcut, IPointcutAdvisor, IOrdered
{
private int _order = Int32.MaxValue;
private IAdvice _advice;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.StaticMethodMatcherPointcutAdvisor"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
protected StaticMethodMatcherPointcutAdvisor()
{
}
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.AbstractRegularExpressionMethodPointcut"/>
/// class for the supplied <paramref name="advice"/>
/// </summary>
/// <remarks>
/// <p>
/// This is an abstract class, and as such has no publicly
/// visible constructors.
/// </p>
/// </remarks>
/// <param name="advice">
/// The advice to use.
/// </param>
public StaticMethodMatcherPointcutAdvisor(IAdvice advice)
{
this._advice = advice;
}
/// <summary>
/// Is this advice associated with a particular instance?
/// </summary>
/// <value>
/// <see langword="true"/> if this advice is associated with a
/// particular instance.
/// </value>
/// <exception cref="System.NotSupportedException">
/// Always; this property is not yet supported.
/// </exception>
public virtual bool IsPerInstance
{
get
{
throw new NotSupportedException(
"The 'IsPerInstance' property of the IAdvisor interface is " +
"not yet supported in Spring.NET.");
}
}
/// <summary>
/// Returns this <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </summary>
/// <returns>
/// This <see cref="Spring.Aop.IAdvisor"/>s order in the
/// interception chain.
/// </returns>
public virtual int Order
{
get { return this._order; }
set { this._order = value; }
}
/// <summary>
/// Return the advice part of this advisor.
/// </summary>
/// <returns>
/// The advice that should apply if the pointcut matches.
/// </returns>
/// <see cref="Spring.Aop.IAdvisor.Advice"/>
public virtual IAdvice Advice
{
get { return this._advice; }
set { this._advice = value; }
}
/// <summary>
/// The <see cref="Spring.Aop.IPointcut"/> that drives this advisor.
/// </summary>
public virtual IPointcut Pointcut
{
get { return this; }
}
}
}

View File

@@ -1,158 +1,157 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Defines miscellaneous <see cref="System.Type"/> filter operations.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
/// <version>$Id: TypeFilters.cs,v 1.4 2007/03/16 04:01:25 aseovic Exp $</version>
public sealed class TypeFilters
{
/// <summary>
/// Creates a union of two <see cref="System.Type"/> filters.
/// </summary>
/// <remarks>
/// <p>
/// The filter arising from the union will match all of the
/// <see cref="System.Type"/> that either of the two supplied filters
/// would match.
/// </p>
/// </remarks>
/// <param name="first">
/// The first <see cref="System.Type"/> filter.
/// </param>
/// <param name="second">
/// The second <see cref="System.Type"/> filter.
/// </param>
/// <returns>
/// The union of the supplied <see cref="System.Type"/> filters.
/// </returns>
public static ITypeFilter Union(ITypeFilter first, ITypeFilter second)
{
return new UnionTypeFilter(new ITypeFilter[] {first, second});
}
/// <summary>
/// Creates the intersection of two <see cref="System.Type"/> filters.
/// </summary>
/// <remarks>
/// <p>
/// The filter arising from the intersection will match all of the
/// <see cref="System.Type"/> that both of the two supplied filters
/// would match.
/// </p>
/// </remarks>
/// <param name="first">
/// The first <see cref="System.Type"/> filter.
/// </param>
/// <param name="second">
/// The second <see cref="System.Type"/> filter.
/// </param>
/// <returns>
/// The intersection of the supplied <see cref="System.Type"/> filters.
/// </returns>
public static ITypeFilter Intersection(ITypeFilter first, ITypeFilter second)
{
return new IntersectionTypeFilter(new ITypeFilter[] {first, second});
}
/// <summary>
/// Union class filter implementation.
/// </summary>
[Serializable]
private sealed class UnionTypeFilter : ITypeFilter
{
private ITypeFilter[] _filters;
public UnionTypeFilter(ITypeFilter[] filters)
{
_filters = filters;
}
public bool Matches(Type type)
{
for (int i = 0; i < _filters.Length; i++)
{
if (_filters[i].Matches(type))
{
return true;
}
}
return false;
}
}
/// <summary>
/// Intersection <see cref="Spring.Aop.ITypeFilter"/> implementation.
/// </summary>
[Serializable]
private sealed class IntersectionTypeFilter : ITypeFilter
{
private ITypeFilter[] _filters;
public IntersectionTypeFilter(ITypeFilter[] filters)
{
_filters = filters;
}
public bool Matches(Type type)
{
for (int i = 0; i < _filters.Length; i++)
{
if (!_filters[i].Matches(type))
{
return false;
}
}
return true;
}
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.TypeFilters"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible constructors.
/// </p>
/// </remarks>
private TypeFilters()
{
}
// CLOVER:ON
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Defines miscellaneous <see cref="System.Type"/> filter operations.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
public sealed class TypeFilters
{
/// <summary>
/// Creates a union of two <see cref="System.Type"/> filters.
/// </summary>
/// <remarks>
/// <p>
/// The filter arising from the union will match all of the
/// <see cref="System.Type"/> that either of the two supplied filters
/// would match.
/// </p>
/// </remarks>
/// <param name="first">
/// The first <see cref="System.Type"/> filter.
/// </param>
/// <param name="second">
/// The second <see cref="System.Type"/> filter.
/// </param>
/// <returns>
/// The union of the supplied <see cref="System.Type"/> filters.
/// </returns>
public static ITypeFilter Union(ITypeFilter first, ITypeFilter second)
{
return new UnionTypeFilter(new ITypeFilter[] {first, second});
}
/// <summary>
/// Creates the intersection of two <see cref="System.Type"/> filters.
/// </summary>
/// <remarks>
/// <p>
/// The filter arising from the intersection will match all of the
/// <see cref="System.Type"/> that both of the two supplied filters
/// would match.
/// </p>
/// </remarks>
/// <param name="first">
/// The first <see cref="System.Type"/> filter.
/// </param>
/// <param name="second">
/// The second <see cref="System.Type"/> filter.
/// </param>
/// <returns>
/// The intersection of the supplied <see cref="System.Type"/> filters.
/// </returns>
public static ITypeFilter Intersection(ITypeFilter first, ITypeFilter second)
{
return new IntersectionTypeFilter(new ITypeFilter[] {first, second});
}
/// <summary>
/// Union class filter implementation.
/// </summary>
[Serializable]
private sealed class UnionTypeFilter : ITypeFilter
{
private ITypeFilter[] _filters;
public UnionTypeFilter(ITypeFilter[] filters)
{
_filters = filters;
}
public bool Matches(Type type)
{
for (int i = 0; i < _filters.Length; i++)
{
if (_filters[i].Matches(type))
{
return true;
}
}
return false;
}
}
/// <summary>
/// Intersection <see cref="Spring.Aop.ITypeFilter"/> implementation.
/// </summary>
[Serializable]
private sealed class IntersectionTypeFilter : ITypeFilter
{
private ITypeFilter[] _filters;
public IntersectionTypeFilter(ITypeFilter[] filters)
{
_filters = filters;
}
public bool Matches(Type type)
{
for (int i = 0; i < _filters.Length; i++)
{
if (!_filters[i].Matches(type))
{
return false;
}
}
return true;
}
}
#region Constructor (s) / Destructor
// CLOVER:OFF
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.TypeFilters"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible constructors.
/// </p>
/// </remarks>
private TypeFilters()
{
}
// CLOVER:ON
#endregion
}
}

View File

@@ -1,124 +1,123 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// A <see cref="Spring.Aop.IPointcut"/> union.
/// </summary>
/// <remarks>
/// <p>
/// Such pointcut unions are tricky, because one cannot simply <c>OR</c>
/// the respective <see cref="Spring.Aop.IMethodMatcher"/>s: one has to
/// ascertain that each <see cref="Spring.Aop.IMethodMatcher"/>'s
/// <see cref="Spring.Aop.IPointcut.TypeFilter"/> is also satisfied.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: UnionPointcut.cs,v 1.8 2007/03/16 04:01:25 aseovic Exp $</version>
[Serializable]
internal class UnionPointcut : IPointcut
{
private IPointcut a;
private IPointcut b;
private IMethodMatcher mm;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.UnionPointcut"/> class.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
public UnionPointcut(IPointcut firstPointcut, IPointcut secondPointcut)
{
this.a = firstPointcut;
this.b = secondPointcut;
this.mm = new PointcutUnionMethodMatcher(this);
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter
{
get { return TypeFilters.Union(a.TypeFilter, b.TypeFilter); }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public IMethodMatcher MethodMatcher
{
get { return mm; }
}
/// <summary>
/// Internal method matcher class for union pointcut.
/// </summary>
private sealed class PointcutUnionMethodMatcher : IMethodMatcher
{
private UnionPointcut _enclosingInstance;
public PointcutUnionMethodMatcher(UnionPointcut enclosingInstance)
{
this._enclosingInstance = enclosingInstance;
}
public bool IsRuntime
{
get
{
return _enclosingInstance.a.MethodMatcher.IsRuntime
|| _enclosingInstance.b.MethodMatcher.IsRuntime;
}
}
public bool Matches(MethodInfo method, Type targetType)
{
return (_enclosingInstance.a.TypeFilter.Matches(targetType)
&& _enclosingInstance.a.MethodMatcher.Matches(method, targetType))
|| (_enclosingInstance.b.TypeFilter.Matches(targetType)
&& _enclosingInstance.b.MethodMatcher.Matches(method, targetType));
}
public bool Matches(MethodInfo method, Type targetType, object[] args)
{
// 2-arg matcher will already have run, so we don't need to do type filtering again...
return _enclosingInstance.a.MethodMatcher.Matches(method, targetType, args)
|| _enclosingInstance.b.MethodMatcher.Matches(method, targetType, args);
}
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// A <see cref="Spring.Aop.IPointcut"/> union.
/// </summary>
/// <remarks>
/// <p>
/// Such pointcut unions are tricky, because one cannot simply <c>OR</c>
/// the respective <see cref="Spring.Aop.IMethodMatcher"/>s: one has to
/// ascertain that each <see cref="Spring.Aop.IMethodMatcher"/>'s
/// <see cref="Spring.Aop.IPointcut.TypeFilter"/> is also satisfied.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
internal class UnionPointcut : IPointcut
{
private IPointcut a;
private IPointcut b;
private IMethodMatcher mm;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Support.UnionPointcut"/> class.
/// </summary>
/// <param name="firstPointcut">The first pointcut.</param>
/// <param name="secondPointcut">The second pointcut.</param>
public UnionPointcut(IPointcut firstPointcut, IPointcut secondPointcut)
{
this.a = firstPointcut;
this.b = secondPointcut;
this.mm = new PointcutUnionMethodMatcher(this);
}
/// <summary>
/// The <see cref="Spring.Aop.ITypeFilter"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.ITypeFilter"/>.
/// </value>
public ITypeFilter TypeFilter
{
get { return TypeFilters.Union(a.TypeFilter, b.TypeFilter); }
}
/// <summary>
/// The <see cref="Spring.Aop.IMethodMatcher"/> for this pointcut.
/// </summary>
/// <value>
/// The current <see cref="Spring.Aop.IMethodMatcher"/>.
/// </value>
public IMethodMatcher MethodMatcher
{
get { return mm; }
}
/// <summary>
/// Internal method matcher class for union pointcut.
/// </summary>
private sealed class PointcutUnionMethodMatcher : IMethodMatcher
{
private UnionPointcut _enclosingInstance;
public PointcutUnionMethodMatcher(UnionPointcut enclosingInstance)
{
this._enclosingInstance = enclosingInstance;
}
public bool IsRuntime
{
get
{
return _enclosingInstance.a.MethodMatcher.IsRuntime
|| _enclosingInstance.b.MethodMatcher.IsRuntime;
}
}
public bool Matches(MethodInfo method, Type targetType)
{
return (_enclosingInstance.a.TypeFilter.Matches(targetType)
&& _enclosingInstance.a.MethodMatcher.Matches(method, targetType))
|| (_enclosingInstance.b.TypeFilter.Matches(targetType)
&& _enclosingInstance.b.MethodMatcher.Matches(method, targetType));
}
public bool Matches(MethodInfo method, Type targetType, object[] args)
{
// 2-arg matcher will already have run, so we don't need to do type filtering again...
return _enclosingInstance.a.MethodMatcher.Matches(method, targetType, args)
|| _enclosingInstance.b.MethodMatcher.Matches(method, targetType, args);
}
}
}
}

View File

@@ -1,204 +1,203 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Aop.Support;
using Spring.Objects;
using Spring.Objects.Factory;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Abstract superclass for pooling <see cref="Spring.Aop.ITargetSource"/>s.
/// </summary>
/// <remarks>
/// <p>
/// Maintains a pool of target instances, acquiring and releasing a target
/// object from the pool for each method invocation.
/// </p>
/// <p>
/// This class is independent of pooling technology.
/// </p>
/// <p>
/// Subclasses must implement the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.GetTarget"/> and
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.ReleaseTarget"/>
/// methods to work with their chosen pool. The
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource.NewPrototypeInstance"/>
/// method inherited from the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource"/> base class
/// can be used to create objects to put in the pool. Subclasses must also
/// implement some of the monitoring methods from the
/// <see cref="Spring.Aop.Target.PoolingConfig"/> interface. This class
/// provides the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.GetPoolingConfigMixin"/>
/// method to return an <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// making these statistics available on proxied objects.
/// </p>
/// <p>
/// This class implements the <see cref="System.IDisposable"/> interface in
/// order to force subclasses to implement the
/// <see cref="System.IDisposable.Dispose"/> method to cleanup and close
/// down their pool.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
/// <version>$Id: AbstractPoolingTargetSource.cs,v 1.7 2007/03/16 04:01:26 aseovic Exp $</version>
[Serializable]
public abstract class AbstractPoolingTargetSource
: AbstractPrototypeTargetSource, PoolingConfig, IDisposable, IAdvice
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected AbstractPoolingTargetSource()
{
}
#endregion
/// <summary>
/// Returns the target object (acquired from the pool).
/// </summary>
/// <returns>The target object (acquired from the pool).</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public abstract override object GetTarget();
/// <summary>
/// Gets the <see cref="Spring.Aop.Target.PoolingConfig"/> mixin.
/// </summary>
/// <returns>
/// An <see cref="Spring.Aop.IIntroductionAdvisor"/> exposing statistics
/// about the pool maintained by this object.
/// </returns>
public DefaultIntroductionAdvisor GetPoolingConfigMixin()
{
return new DefaultIntroductionAdvisor(this, typeof (PoolingConfig));
}
/// <summary>
/// The maximum number of object instances in this pool.
/// </summary>
public int MaxSize
{
get { return _maxSize; }
set { _maxSize = value; }
}
/// <summary>
/// The number of active object instances in this pool.
/// </summary>
public abstract int Active { get; }
/// <summary>
/// The number of free object instances in this pool.
/// </summary>
public abstract int Free { get; }
/// <summary>
/// The target factory that will be used to perform the lookup
/// of the object referred to by the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource.TargetObjectName"/>
/// property.
/// </summary>
/// <value>
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (will never be <see langword="null"/>).
/// </value>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
/// <seealso cref="Spring.Aop.Target.AbstractPrototypeTargetSource.ObjectFactory"/>
public override IObjectFactory ObjectFactory
{
set
{
base.ObjectFactory = value;
try
{
CreatePool(value);
}
catch (ObjectsException)
{
throw;
}
catch (Exception ex)
{
throw new ObjectInitializationException("Could not create instance pool.", ex);
}
}
}
/// <summary>
/// Create the pool.
/// </summary>
/// <param name="factory">
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>, in
/// case one needs collaborators from it (normally one's own properties
/// are sufficient).
/// </param>
/// <exception cref="System.Exception">
/// In the case of errors encountered during the creation of the pool.
/// </exception>
protected abstract void CreatePool(IObjectFactory factory);
/// <summary>
/// Releases the target object (returns it to the pool).
/// </summary>
/// <param name="target">
/// The target object to release (return to the pool).
/// </param>
/// <exception cref="System.Exception">
/// In the case that the <paramref name="target"/> could not be released.
/// </exception>
public abstract override void ReleaseTarget(object target);
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources.
/// </summary>
/// <remarks>
/// <p>
/// Disposes of the pool.
/// </p>
/// </remarks>
public abstract void Dispose();
private int _maxSize;
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using Spring.Aop.Support;
using Spring.Objects;
using Spring.Objects.Factory;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Abstract superclass for pooling <see cref="Spring.Aop.ITargetSource"/>s.
/// </summary>
/// <remarks>
/// <p>
/// Maintains a pool of target instances, acquiring and releasing a target
/// object from the pool for each method invocation.
/// </p>
/// <p>
/// This class is independent of pooling technology.
/// </p>
/// <p>
/// Subclasses must implement the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.GetTarget"/> and
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.ReleaseTarget"/>
/// methods to work with their chosen pool. The
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource.NewPrototypeInstance"/>
/// method inherited from the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource"/> base class
/// can be used to create objects to put in the pool. Subclasses must also
/// implement some of the monitoring methods from the
/// <see cref="Spring.Aop.Target.PoolingConfig"/> interface. This class
/// provides the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource.GetPoolingConfigMixin"/>
/// method to return an <see cref="Spring.Aop.IIntroductionAdvisor"/>
/// making these statistics available on proxied objects.
/// </p>
/// <p>
/// This class implements the <see cref="System.IDisposable"/> interface in
/// order to force subclasses to implement the
/// <see cref="System.IDisposable.Dispose"/> method to cleanup and close
/// down their pool.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
[Serializable]
public abstract class AbstractPoolingTargetSource
: AbstractPrototypeTargetSource, PoolingConfig, IDisposable, IAdvice
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.AbstractPoolingTargetSource"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected AbstractPoolingTargetSource()
{
}
#endregion
/// <summary>
/// Returns the target object (acquired from the pool).
/// </summary>
/// <returns>The target object (acquired from the pool).</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public abstract override object GetTarget();
/// <summary>
/// Gets the <see cref="Spring.Aop.Target.PoolingConfig"/> mixin.
/// </summary>
/// <returns>
/// An <see cref="Spring.Aop.IIntroductionAdvisor"/> exposing statistics
/// about the pool maintained by this object.
/// </returns>
public DefaultIntroductionAdvisor GetPoolingConfigMixin()
{
return new DefaultIntroductionAdvisor(this, typeof (PoolingConfig));
}
/// <summary>
/// The maximum number of object instances in this pool.
/// </summary>
public int MaxSize
{
get { return _maxSize; }
set { _maxSize = value; }
}
/// <summary>
/// The number of active object instances in this pool.
/// </summary>
public abstract int Active { get; }
/// <summary>
/// The number of free object instances in this pool.
/// </summary>
public abstract int Free { get; }
/// <summary>
/// The target factory that will be used to perform the lookup
/// of the object referred to by the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource.TargetObjectName"/>
/// property.
/// </summary>
/// <value>
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (will never be <see langword="null"/>).
/// </value>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
/// <seealso cref="Spring.Aop.Target.AbstractPrototypeTargetSource.ObjectFactory"/>
public override IObjectFactory ObjectFactory
{
set
{
base.ObjectFactory = value;
try
{
CreatePool(value);
}
catch (ObjectsException)
{
throw;
}
catch (Exception ex)
{
throw new ObjectInitializationException("Could not create instance pool.", ex);
}
}
}
/// <summary>
/// Create the pool.
/// </summary>
/// <param name="factory">
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>, in
/// case one needs collaborators from it (normally one's own properties
/// are sufficient).
/// </param>
/// <exception cref="System.Exception">
/// In the case of errors encountered during the creation of the pool.
/// </exception>
protected abstract void CreatePool(IObjectFactory factory);
/// <summary>
/// Releases the target object (returns it to the pool).
/// </summary>
/// <param name="target">
/// The target object to release (return to the pool).
/// </param>
/// <exception cref="System.Exception">
/// In the case that the <paramref name="target"/> could not be released.
/// </exception>
public abstract override void ReleaseTarget(object target);
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources.
/// </summary>
/// <remarks>
/// <p>
/// Disposes of the pool.
/// </p>
/// </remarks>
public abstract void Dispose();
private int _maxSize;
}
}

View File

@@ -1,238 +1,237 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Globalization;
using Common.Logging;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Support;
using Spring.Util;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Base class for dynamic <see cref="Spring.Aop.ITargetSource"/>
/// implementations that can create new prototype object instances to
/// support a pooling or new-instance-per-invocation strategy.
/// </summary>
/// <remarks>
/// <p>
/// All such <see cref="Spring.Aop.ITargetSource"/>s must run in an
/// <see cref="Spring.Objects.Factory.IObjectFactory"/>, as they need to
/// call the <see cref="Spring.Objects.Factory.IObjectFactory.GetObject(string)"/>
/// method to create a new prototype instance.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
/// <version>$Id: AbstractPrototypeTargetSource.cs,v 1.11 2007/07/28 07:32:52 markpollack Exp $</version>
public abstract class AbstractPrototypeTargetSource
: ITargetSource, IObjectFactoryAware, IInitializingObject
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected AbstractPrototypeTargetSource()
{
}
#endregion
#region Properties
/// <summary>
/// The name of the target object to be created on each invocation.
/// </summary>
/// <remarks>
/// <p>
/// This object should be a prototype, or the same instance will always
/// be obtained from the owning <see cref="ObjectFactory"/>.
/// </p>
/// </remarks>
public virtual string TargetObjectName
{
get { return _targetObjectName; }
set {
_targetObjectName = value;
}
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
public virtual Type TargetType
{
get { return _targetType; }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public virtual bool IsStatic
{
get { return false; }
}
/// <summary>
/// The target factory that will be used to perform the lookup
/// of the object referred to by the <see cref="TargetObjectName"/>
/// property.
/// </summary>
/// <remarks>
/// <p>
/// Needed so that prototype instances can be created as necessary.
/// </p>
/// </remarks>
/// <value>
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (will never be <see langword="null"/>).
/// </value>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
/// <seealso cref="Spring.Objects.Factory.IObjectFactoryAware.ObjectFactory"/>
public virtual IObjectFactory ObjectFactory
{
get { return _owningObjectFactory; }
set
{
_owningObjectFactory = value;
if (!value.IsPrototype(TargetObjectName))
{
throw new ObjectDefinitionStoreException(
"Cannot use PrototypeTargetSource against a " +
"Singleton object; instances would not be independent.");
}
#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format(
"Getting object with name '{0}' to determine class.",
TargetObjectName));
}
#endregion
_targetType = _owningObjectFactory.GetType(TargetObjectName);
}
}
#endregion
#region Methods
/// <summary>
/// Subclasses should use this method to create a new prototype instance.
/// </summary>
protected virtual object NewPrototypeInstance()
{
#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format(
"Creating new target from object '{0}'.",
TargetObjectName));
}
#endregion
return ObjectFactory.GetObject(TargetObjectName);
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public abstract object GetTarget();
/// <summary>
/// Releases the target object.
/// </summary>
/// <param name="target">The target object to release.</param>
public virtual void ReleaseTarget(object target)
{
}
/// <summary>
/// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// after it has set all object properties supplied
/// (and satisfied the
/// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>
/// and <see cref="Spring.Context.IApplicationContextAware"/>
/// interfaces).
/// </summary>
/// <remarks>
/// <p>
/// Ensures that the <see cref="TargetObjectName"/> property has been
/// set to a valid value (i.e. is not <see langword="null"/> or a string
/// that consists solely of whitespace).
/// </p>
/// </remarks>
/// <exception cref="System.Exception">
/// In the event of misconfiguration (such as failure to set an essential
/// property) or if initialization fails.
/// </exception>
/// <seealso cref="Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
public virtual void AfterPropertiesSet()
{
AssertUtils.ArgumentHasText(
TargetObjectName, "TargetObjectName",
"The 'TargetObjectName' property must have a value.");
}
#endregion
#region Fields
/// <summary>
/// The shared <see cref="Common.Logging.ILog"/> instance for this class (and derived classes).
/// </summary>
protected readonly ILog logger = LogManager.GetLogger(typeof (AbstractPrototypeTargetSource));
private String _targetObjectName;
private IObjectFactory _owningObjectFactory;
private Type _targetType;
#endregion
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Globalization;
using Common.Logging;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Support;
using Spring.Util;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Base class for dynamic <see cref="Spring.Aop.ITargetSource"/>
/// implementations that can create new prototype object instances to
/// support a pooling or new-instance-per-invocation strategy.
/// </summary>
/// <remarks>
/// <p>
/// All such <see cref="Spring.Aop.ITargetSource"/>s must run in an
/// <see cref="Spring.Objects.Factory.IObjectFactory"/>, as they need to
/// call the <see cref="Spring.Objects.Factory.IObjectFactory.GetObject(string)"/>
/// method to create a new prototype instance.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
public abstract class AbstractPrototypeTargetSource
: ITargetSource, IObjectFactoryAware, IInitializingObject
{
#region Constructor (s) / Destructor
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.AbstractPrototypeTargetSource"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected AbstractPrototypeTargetSource()
{
}
#endregion
#region Properties
/// <summary>
/// The name of the target object to be created on each invocation.
/// </summary>
/// <remarks>
/// <p>
/// This object should be a prototype, or the same instance will always
/// be obtained from the owning <see cref="ObjectFactory"/>.
/// </p>
/// </remarks>
public virtual string TargetObjectName
{
get { return _targetObjectName; }
set {
_targetObjectName = value;
}
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
public virtual Type TargetType
{
get { return _targetType; }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public virtual bool IsStatic
{
get { return false; }
}
/// <summary>
/// The target factory that will be used to perform the lookup
/// of the object referred to by the <see cref="TargetObjectName"/>
/// property.
/// </summary>
/// <remarks>
/// <p>
/// Needed so that prototype instances can be created as necessary.
/// </p>
/// </remarks>
/// <value>
/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// (will never be <see langword="null"/>).
/// </value>
/// <exception cref="Spring.Objects.ObjectsException">
/// In case of initialization errors.
/// </exception>
/// <seealso cref="Spring.Objects.Factory.IObjectFactoryAware.ObjectFactory"/>
public virtual IObjectFactory ObjectFactory
{
get { return _owningObjectFactory; }
set
{
_owningObjectFactory = value;
if (!value.IsPrototype(TargetObjectName))
{
throw new ObjectDefinitionStoreException(
"Cannot use PrototypeTargetSource against a " +
"Singleton object; instances would not be independent.");
}
#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format(
"Getting object with name '{0}' to determine class.",
TargetObjectName));
}
#endregion
_targetType = _owningObjectFactory.GetType(TargetObjectName);
}
}
#endregion
#region Methods
/// <summary>
/// Subclasses should use this method to create a new prototype instance.
/// </summary>
protected virtual object NewPrototypeInstance()
{
#region Instrumentation
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format(
"Creating new target from object '{0}'.",
TargetObjectName));
}
#endregion
return ObjectFactory.GetObject(TargetObjectName);
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public abstract object GetTarget();
/// <summary>
/// Releases the target object.
/// </summary>
/// <param name="target">The target object to release.</param>
public virtual void ReleaseTarget(object target)
{
}
/// <summary>
/// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
/// after it has set all object properties supplied
/// (and satisfied the
/// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>
/// and <see cref="Spring.Context.IApplicationContextAware"/>
/// interfaces).
/// </summary>
/// <remarks>
/// <p>
/// Ensures that the <see cref="TargetObjectName"/> property has been
/// set to a valid value (i.e. is not <see langword="null"/> or a string
/// that consists solely of whitespace).
/// </p>
/// </remarks>
/// <exception cref="System.Exception">
/// In the event of misconfiguration (such as failure to set an essential
/// property) or if initialization fails.
/// </exception>
/// <seealso cref="Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet"/>
public virtual void AfterPropertiesSet()
{
AssertUtils.ArgumentHasText(
TargetObjectName, "TargetObjectName",
"The 'TargetObjectName' property must have a value.");
}
#endregion
#region Fields
/// <summary>
/// The shared <see cref="Common.Logging.ILog"/> instance for this class (and derived classes).
/// </summary>
protected readonly ILog logger = LogManager.GetLogger(typeof (AbstractPrototypeTargetSource));
private String _targetObjectName;
private IObjectFactory _owningObjectFactory;
private Type _targetType;
#endregion
}
}

View File

@@ -1,161 +1,160 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// The <see cref="Spring.Aop.ITargetSource"/> to be used
/// when there is no target object, and behavior is supplied by the
/// advisors.
/// </summary>
/// <remarks>
/// <p>
/// This class is exposed as a singleton.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: EmptyTargetSource.cs,v 1.4 2007/10/08 22:04:51 markpollack Exp $</version>
[Serializable]
public sealed class EmptyTargetSource : ITargetSource, ISerializable
{
/// <summary>
/// The <see cref="Spring.Aop.ITargetSource"/> to be used
/// when there is no target object, and behavior is supplied by the
/// advisors.
/// </summary>
public static readonly ITargetSource Empty = new EmptyTargetSource();
private object _dummyTarget = new object();
/// <summary>
/// Creates a new instance of the
/// <see cref="EmptyTargetSource"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible constructors.
/// </p>
/// </remarks>
private EmptyTargetSource()
{
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
public Type TargetType
{
get { return typeof(object); }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="Spring.Aop.Target.EmptyTargetSource.Empty"/>
/// instance is static, and this always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public bool IsStatic
{
get { return true; }
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public object GetTarget()
{
return _dummyTarget;
}
/// <summary>
/// Releases the target object.
/// </summary>
/// <remarks>
/// <note type="implementnotes">
/// This is a no-op operation in this implementation.
/// </note>
/// </remarks>
/// <param name="target">The target object to release.</param>
public void ReleaseTarget(object target)
{
}
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.ITargetSource"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.ITargetSource"/>.
/// </returns>
public override string ToString()
{
return "EmptyTargetSource: no target";
}
/// <summary>
/// Populates a <see cref="System.Runtime.Serialization.SerializationInfo"/> with
/// the data needed to serialize the target object.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate
/// with data.
/// </param>
/// <param name="context">
/// The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>)
/// for this serialization.
/// </param>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.SetType(typeof (EmptyTargetSourceObjectReference));
}
[Serializable]
private sealed class EmptyTargetSourceObjectReference : IObjectReference
{
public object GetRealObject(StreamingContext context)
{
return EmptyTargetSource.Empty;
}
}
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// The <see cref="Spring.Aop.ITargetSource"/> to be used
/// when there is no target object, and behavior is supplied by the
/// advisors.
/// </summary>
/// <remarks>
/// <p>
/// This class is exposed as a singleton.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.NET)</author>
[Serializable]
public sealed class EmptyTargetSource : ITargetSource, ISerializable
{
/// <summary>
/// The <see cref="Spring.Aop.ITargetSource"/> to be used
/// when there is no target object, and behavior is supplied by the
/// advisors.
/// </summary>
public static readonly ITargetSource Empty = new EmptyTargetSource();
private object _dummyTarget = new object();
/// <summary>
/// Creates a new instance of the
/// <see cref="EmptyTargetSource"/> class.
/// </summary>
/// <remarks>
/// <p>
/// This is a utility class, and as such has no publicly visible constructors.
/// </p>
/// </remarks>
private EmptyTargetSource()
{
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
public Type TargetType
{
get { return typeof(object); }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <remarks>
/// <p>
/// The <see cref="Spring.Aop.Target.EmptyTargetSource.Empty"/>
/// instance is static, and this always returns <see langword="true"/>.
/// </p>
/// </remarks>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public bool IsStatic
{
get { return true; }
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public object GetTarget()
{
return _dummyTarget;
}
/// <summary>
/// Releases the target object.
/// </summary>
/// <remarks>
/// <note type="implementnotes">
/// This is a no-op operation in this implementation.
/// </note>
/// </remarks>
/// <param name="target">The target object to release.</param>
public void ReleaseTarget(object target)
{
}
/// <summary>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.ITargetSource"/>.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents the current
/// <see cref="Spring.Aop.ITargetSource"/>.
/// </returns>
public override string ToString()
{
return "EmptyTargetSource: no target";
}
/// <summary>
/// Populates a <see cref="System.Runtime.Serialization.SerializationInfo"/> with
/// the data needed to serialize the target object.
/// </summary>
/// <param name="info">
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/> to populate
/// with data.
/// </param>
/// <param name="context">
/// The destination (see <see cref="System.Runtime.Serialization.StreamingContext"/>)
/// for this serialization.
/// </param>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.SetType(typeof (EmptyTargetSourceObjectReference));
}
[Serializable]
private sealed class EmptyTargetSourceObjectReference : IObjectReference
{
public object GetRealObject(StreamingContext context)
{
return EmptyTargetSource.Empty;
}
}
}
}

View File

@@ -1,172 +1,171 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// <see cref="Spring.Aop.ITargetSource"/> implementation that caches a
/// local target object, but allows the target to be swapped while the
/// application is running
/// </summary>
/// <remarks>
/// <p>
/// If configuring an object of this class in a Spring IoC container,
/// use constructor injection to supply the intial target.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
/// <version>$Id: HotSwappableTargetSource.cs,v 1.6 2007/03/16 04:01:26 aseovic Exp $</version>
[Serializable]
public class HotSwappableTargetSource : ITargetSource
{
private object _target;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.HotSwappableTargetSource"/> with the initial target.
/// </summary>
/// <param name="initialTarget">
/// The initial target. May be <see langword="null"/>.
/// </param>
public HotSwappableTargetSource(object initialTarget)
{
_target = initialTarget;
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
/// <remarks>
/// <p>
/// Can return <see langword="null"/>.
/// </p>
/// </remarks>
public virtual Type TargetType
{
get { return _target.GetType(); }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public virtual bool IsStatic
{
get { return false; }
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public object GetTarget()
{
// synchronization around something that takes so little time is fine...
lock (this)
{
return _target;
}
}
/// <summary>
/// Releases the target object.
/// </summary>
/// <remarks>
/// <p>
/// No-op implementation.
/// </p>
/// </remarks>
/// <param name="target">The target object to release.</param>
public virtual void ReleaseTarget(Object target)
{
}
/// <summary>
/// Swap the target, returning the old target.
/// </summary>
/// <param name="newTarget">The new target.</param>
/// <returns>The old target.</returns>
/// <exception cref="System.ArgumentNullException">
/// If the new target is <see langword="null"/>.
/// </exception>
public virtual object Swap(object newTarget)
{
AssertUtils.ArgumentNotNull(newTarget, "newTarget", "Cannot swap to null.");
lock (this)
{
// TODO: type checks
object old = _target;
_target = newTarget;
return old;
}
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/>
/// is equal to the current <see cref="System.Object"/>.
/// </summary>
/// <remarks>
/// <p>
/// Two invoker interceptors are equal if they have the same target or
/// if the targets are equal.
/// </p>
/// </remarks>
/// <param name="other">The target source to compare with.</param>
/// <returns>
/// <see langword="true"/> if this instance is equal to the
/// specified <see cref="System.Object"/>.
/// </returns>
public override bool Equals(object other)
{
HotSwappableTargetSource otherTargetSource = other as HotSwappableTargetSource;
if (other == null)
{
return false;
}
return otherTargetSource._target == _target || otherTargetSource._target.Equals(_target);
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for use
/// in hashing algorithms and data structures like a hash table.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return base.GetHashCode() + 13 *
(_target == null ? 0 : _target.GetHashCode());
}
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using Spring.Util;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// <see cref="Spring.Aop.ITargetSource"/> implementation that caches a
/// local target object, but allows the target to be swapped while the
/// application is running
/// </summary>
/// <remarks>
/// <p>
/// If configuring an object of this class in a Spring IoC container,
/// use constructor injection to supply the intial target.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Aleksandar Seovic (.Net)</author>
[Serializable]
public class HotSwappableTargetSource : ITargetSource
{
private object _target;
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Aop.Target.HotSwappableTargetSource"/> with the initial target.
/// </summary>
/// <param name="initialTarget">
/// The initial target. May be <see langword="null"/>.
/// </param>
public HotSwappableTargetSource(object initialTarget)
{
_target = initialTarget;
}
/// <summary>
/// The <see cref="System.Type"/> of the target object.
/// </summary>
/// <remarks>
/// <p>
/// Can return <see langword="null"/>.
/// </p>
/// </remarks>
public virtual Type TargetType
{
get { return _target.GetType(); }
}
/// <summary>
/// Is the target source static?
/// </summary>
/// <value>
/// <see langword="true"/> if the target source is static.
/// </value>
public virtual bool IsStatic
{
get { return false; }
}
/// <summary>
/// Returns the target object.
/// </summary>
/// <returns>The target object.</returns>
/// <exception cref="System.Exception">
/// If unable to obtain the target object.
/// </exception>
public object GetTarget()
{
// synchronization around something that takes so little time is fine...
lock (this)
{
return _target;
}
}
/// <summary>
/// Releases the target object.
/// </summary>
/// <remarks>
/// <p>
/// No-op implementation.
/// </p>
/// </remarks>
/// <param name="target">The target object to release.</param>
public virtual void ReleaseTarget(Object target)
{
}
/// <summary>
/// Swap the target, returning the old target.
/// </summary>
/// <param name="newTarget">The new target.</param>
/// <returns>The old target.</returns>
/// <exception cref="System.ArgumentNullException">
/// If the new target is <see langword="null"/>.
/// </exception>
public virtual object Swap(object newTarget)
{
AssertUtils.ArgumentNotNull(newTarget, "newTarget", "Cannot swap to null.");
lock (this)
{
// TODO: type checks
object old = _target;
_target = newTarget;
return old;
}
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/>
/// is equal to the current <see cref="System.Object"/>.
/// </summary>
/// <remarks>
/// <p>
/// Two invoker interceptors are equal if they have the same target or
/// if the targets are equal.
/// </p>
/// </remarks>
/// <param name="other">The target source to compare with.</param>
/// <returns>
/// <see langword="true"/> if this instance is equal to the
/// specified <see cref="System.Object"/>.
/// </returns>
public override bool Equals(object other)
{
HotSwappableTargetSource otherTargetSource = other as HotSwappableTargetSource;
if (other == null)
{
return false;
}
return otherTargetSource._target == _target || otherTargetSource._target.Equals(_target);
}
/// <summary>
/// Serves as a hash function for a particular type, suitable for use
/// in hashing algorithms and data structures like a hash table.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return base.GetHashCode() + 13 *
(_target == null ? 0 : _target.GetHashCode());
}
}
}

View File

@@ -1,64 +1,63 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Statistics for a thread local <see cref="Spring.Aop.ITargetSource"/>.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
/// <version>$Id: IThreadLocalTargetSourceStats.cs,v 1.3 2006/04/09 07:18:37 markpollack Exp $</version>
public interface IThreadLocalTargetSourceStats
{
/// <summary>
/// Gets the number of invocations of the
/// <see cref="ThreadLocalTargetSource.GetTarget()"/> and
/// <see cref="ThreadLocalTargetSource.Invoke(IMethodInvocation)"/> methods.
/// </summary>
/// <value>
/// The number of invocations of the
/// <see cref="ThreadLocalTargetSource.GetTarget()"/> and
/// <see cref="ThreadLocalTargetSource.Invoke(IMethodInvocation)"/> methods.
/// </value>
int Invocations { get; }
/// <summary>
/// Gets the number of hits that were satisfied by a thread bound object.
/// </summary>
/// <value>
/// The number of hits that were satisfied by a thread bound object.
/// </value>
int Hits { get; }
/// <summary>
/// Gets the number of thread bound objects created.
/// </summary>
/// <value>The number of thread bound objects created.</value>
int Objects { get; }
}
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Statistics for a thread local <see cref="Spring.Aop.ITargetSource"/>.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
public interface IThreadLocalTargetSourceStats
{
/// <summary>
/// Gets the number of invocations of the
/// <see cref="ThreadLocalTargetSource.GetTarget()"/> and
/// <see cref="ThreadLocalTargetSource.Invoke(IMethodInvocation)"/> methods.
/// </summary>
/// <value>
/// The number of invocations of the
/// <see cref="ThreadLocalTargetSource.GetTarget()"/> and
/// <see cref="ThreadLocalTargetSource.Invoke(IMethodInvocation)"/> methods.
/// </value>
int Invocations { get; }
/// <summary>
/// Gets the number of hits that were satisfied by a thread bound object.
/// </summary>
/// <value>
/// The number of hits that were satisfied by a thread bound object.
/// </value>
int Hits { get; }
/// <summary>
/// Gets the number of thread bound objects created.
/// </summary>
/// <value>The number of thread bound objects created.</value>
int Objects { get; }
}
}

Some files were not shown because too many files have changed in this diff Show More