diff --git a/src/Spring/Spring.Aop/Aop/Framework/AutoProxy/ObjectNameAutoProxyCreator.cs b/src/Spring/Spring.Aop/Aop/Framework/AutoProxy/ObjectNameAutoProxyCreator.cs index 890f92f6..c29102f9 100644 --- a/src/Spring/Spring.Aop/Aop/Framework/AutoProxy/ObjectNameAutoProxyCreator.cs +++ b/src/Spring/Spring.Aop/Aop/Framework/AutoProxy/ObjectNameAutoProxyCreator.cs @@ -61,18 +61,23 @@ namespace Spring.Aop.Framework.AutoProxy /// public IList ObjectNames { - set { objectNames = value; } - get { return objectNames; } + set + { + AssertUtils.ArgumentHasElements(value, "ObjectNames"); + objectNames = value; + } + get + { + return objectNames; + } } /// /// Identify as object to proxy if the object name is in the configured list of names. /// protected override bool IsEligibleForProxying( Type targetType, string targetName ) - { - AssertUtils.ArgumentNotNull(this.ObjectNames, "ObjectNames"); - - bool shallProxy = PatternMatchUtils.IsObjectNameMatch(targetType, targetName, this.ObjectNames, new PatternMatchUtils.ObjectNameMatchPredicate(IsMatch), ObjectFactoryUtils.FactoryObjectPrefix); + { + bool shallProxy = IsObjectNameMatch(targetType, targetName, this.ObjectNames); return shallProxy; } @@ -92,5 +97,40 @@ namespace Spring.Aop.Framework.AutoProxy { return PatternMatchUtils.SimpleMatch( mappedName, objectName ); } + + /// + /// Convenience method that may be used by derived classes. Iterates over the list of to match against. + /// + /// the object's type. Must not be null. + /// the name of the object Must not be null. + /// the list of patterns, that shall be matched against. Must not be null. + /// + /// If is null, will always return true, otherwise + /// if matches any of the patterns specified in . + /// + protected bool IsObjectNameMatch(Type objType, string objectName, IList objectNamePatterns) + { + AssertUtils.ArgumentNotNull(objType, "objType"); + AssertUtils.ArgumentNotNull(objectName, "objectName" ); + AssertUtils.ArgumentNotNull(objectNamePatterns, "objectNamePatterns"); + + for (int i = 0; i < objectNamePatterns.Count; i++) + { + string mappedName = (string)objectNamePatterns[i]; + if (typeof(IFactoryObject).IsAssignableFrom(objType)) + { + if (!objectName.StartsWith(ObjectFactoryUtils.FactoryObjectPrefix)) + { + continue; + } + mappedName = mappedName.Substring(ObjectFactoryUtils.FactoryObjectPrefix.Length); + } + if (IsMatch(objectName, mappedName)) + { + return true; + } + } + return false; + } } } \ No newline at end of file diff --git a/src/Spring/Spring.Core/Util/PatternMatchUtils.cs b/src/Spring/Spring.Core/Util/PatternMatchUtils.cs index 8feae635..fd236f5c 100644 --- a/src/Spring/Spring.Core/Util/PatternMatchUtils.cs +++ b/src/Spring/Spring.Core/Util/PatternMatchUtils.cs @@ -22,8 +22,6 @@ using System; using System.Collections; -using System.Reflection; -using System.Text.RegularExpressions; using Spring.Objects.Factory; #endregion @@ -97,55 +95,5 @@ namespace Spring.Util return false; } - /// - /// Signature of callbacks that may be used for matching object names. - /// - /// the object name to check. - /// the pattern to match against. - /// true, if the matches - /// - public delegate bool ObjectNameMatchPredicate(string objectName, string namePattern); - - /// - /// Convenience method that may be used by derived classes. Iterates over the list of to match against. - /// - /// the object's type. Must not be null. - /// the name of the object Must not be null. - /// the list of patterns, that shall be matched against. Must not be null. - /// - /// the used for - /// matching against each pattern in . Must not be null. - /// - /// the prefix to be used for dereferencing factory object names. - /// - /// If is null, will always return true, otherwise - /// if matches any of the patterns specified in . - /// - public static bool IsObjectNameMatch(Type objType, string objectName, IList objectNamePatterns, ObjectNameMatchPredicate isMatchPredicate, string factoryObjectPrefix) - { - AssertUtils.ArgumentNotNull(objType, "objType"); - AssertUtils.ArgumentNotNull(objectName, "objectName"); - AssertUtils.ArgumentNotNull(objectNamePatterns, "objectNamePatterns"); - AssertUtils.ArgumentNotNull(isMatchPredicate, "isMatchPredicate"); - AssertUtils.ArgumentNotNull(factoryObjectPrefix, "factoryObjectPrefix"); - - for (int i = 0; i < objectNamePatterns.Count; i++) - { - string mappedName = (string)objectNamePatterns[i]; - if (typeof( IFactoryObject ).IsAssignableFrom( objType )) - { - if (!objectName.StartsWith( factoryObjectPrefix )) - { - continue; - } - mappedName = mappedName.Substring( factoryObjectPrefix.Length ); - } - if (isMatchPredicate( objectName, mappedName )) - { - return true; - } - } - return false; - } } } \ No newline at end of file