From 6c7e7777df39dba92980de6b74830c1caa51d220 Mon Sep 17 00:00:00 2001 From: sbohlen Date: Thu, 2 Dec 2010 19:00:02 +0000 Subject: [PATCH] removal of Spring.Core.Configuration project and related tests in prep for merge back into trunk --- Spring.Net.2010.sln | 24 -- .../Advice/SpringObjectMethodInterceptor.cs | 92 ------- .../AssemblyObjectDefinitionScanner.cs | 258 ------------------ .../Context/Attributes/AssemblyTypeSource.cs | 51 ---- .../Attributes/ConfigurationAttribute.cs | 74 ----- .../Context/Attributes/ConfigurationClass.cs | 163 ----------- .../Attributes/ConfigurationClassMethod.cs | 123 --------- ...onfigurationClassObjectDefinitionReader.cs | 229 ---------------- .../Attributes/ConfigurationClassParser.cs | 138 ---------- .../ConfigurationClassPostProcessor.cs | 198 -------------- .../Context/Attributes/DefinitionAttribute.cs | 96 ------- .../Context/Attributes/DependsOnAttribute.cs | 45 --- .../Context/Attributes/ImportAttribute.cs | 53 ---- .../Attributes/ImportResourceAttribute.cs | 80 ------ .../Context/Attributes/LazyAttribute.cs | 61 ----- .../Context/Attributes/PrimaryAttribute.cs | 23 -- .../Context/Attributes/ScopeAttribute.cs | 48 ---- .../AttributeConfigObjectDefinitionParser.cs | 43 --- .../ComponentScanObjectDefinitionParser.cs | 15 - .../Context/Config/ContextNamespaceParser.cs | 41 --- .../Context/Config/spring-context-1.3.xsd | 79 ------ .../AssemblyScanningExtensionMethods.cs | 87 ------ .../Properties/AssemblyInfo.cs | 36 --- .../Spring.Core.Configuration.2010.csproj | 88 ------ .../Attributes/AssemblyTypeScannerTests.cs | 101 ------- .../ConfigurationClassPostProcessorTests.cs | 223 --------------- .../Attributes/DefinitionAttributeTests.cs | 38 --- .../ImportResourceAttributeTests.cs | 48 ---- .../Context/Attributes/ObjectDefinitions.xml | 5 - .../AssemblyScanningExtensionMethodsTests.cs | 104 ------- .../Properties/AssemblyInfo.cs | 36 --- ...pring.Core.Configuration.Tests.2010.csproj | 85 ------ 32 files changed, 2785 deletions(-) delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Advice/SpringObjectMethodInterceptor.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyObjectDefinitionScanner.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyTypeSource.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClass.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassMethod.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassObjectDefinitionReader.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassParser.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassPostProcessor.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/DefinitionAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/DependsOnAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ImportAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ImportResourceAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/LazyAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/PrimaryAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Attributes/ScopeAttribute.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Config/AttributeConfigObjectDefinitionParser.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Config/ComponentScanObjectDefinitionParser.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Config/ContextNamespaceParser.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Context/Config/spring-context-1.3.xsd delete mode 100644 src/Spring/Spring.Core.Configuration/Objects/Factory/Support/AssemblyScanningExtensionMethods.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Properties/AssemblyInfo.cs delete mode 100644 src/Spring/Spring.Core.Configuration/Spring.Core.Configuration.2010.csproj delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/AssemblyTypeScannerTests.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ConfigurationClassPostProcessorTests.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/DefinitionAttributeTests.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ImportResourceAttributeTests.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ObjectDefinitions.xml delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Objects/Factory/Support/AssemblyScanningExtensionMethodsTests.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Properties/AssemblyInfo.cs delete mode 100644 test/Spring/Spring.Core.Configuration.Tests/Spring.Core.Configuration.Tests.2010.csproj diff --git a/Spring.Net.2010.sln b/Spring.Net.2010.sln index eb88a143..b1bea551 100644 --- a/Spring.Net.2010.sln +++ b/Spring.Net.2010.sln @@ -74,10 +74,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Web.Mvc.2010", "src\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Web.Mvc.Tests.2010", "test\Spring\Spring.Web.Mvc.Tests\Spring.Web.Mvc.Tests.2010.csproj", "{D4032434-D9A8-437B-95E8-9D4DE0AD9932}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Core.Configuration.2010", "src\Spring\Spring.Core.Configuration\Spring.Core.Configuration.2010.csproj", "{7B65D538-E863-4F57-8DDC-2C38E4150045}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Core.Configuration.Tests.2010", "test\Spring\Spring.Core.Configuration.Tests\Spring.Core.Configuration.Tests.2010.csproj", "{4F1A206C-09A8-43FF-B791-FE956E99A120}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|.NET = Debug|.NET @@ -438,26 +434,6 @@ Global {D4032434-D9A8-437B-95E8-9D4DE0AD9932}.Release|Any CPU.Build.0 = Release|Any CPU {D4032434-D9A8-437B-95E8-9D4DE0AD9932}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {D4032434-D9A8-437B-95E8-9D4DE0AD9932}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Debug|.NET.ActiveCfg = Debug|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Release|.NET.ActiveCfg = Release|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Release|Any CPU.Build.0 = Release|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {7B65D538-E863-4F57-8DDC-2C38E4150045}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Debug|.NET.ActiveCfg = Debug|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Release|.NET.ActiveCfg = Release|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Release|Any CPU.Build.0 = Release|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {4F1A206C-09A8-43FF-B791-FE956E99A120}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Spring/Spring.Core.Configuration/Context/Advice/SpringObjectMethodInterceptor.cs b/src/Spring/Spring.Core.Configuration/Context/Advice/SpringObjectMethodInterceptor.cs deleted file mode 100644 index d3f3a5f0..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Advice/SpringObjectMethodInterceptor.cs +++ /dev/null @@ -1,92 +0,0 @@ -#region License - -/* - * Copyright © 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 - -using System; -using System.Reflection; -using AopAlliance.Intercept; -using Common.Logging; -using Spring.Objects.Factory.Config; -using Spring.Context.Attributes; - -namespace Spring.Context.Advice -{ - /// - /// Intercepts calls to methods within the configuration object - /// - /// Mark Pollack - /// Erich Eichinger - public class SpringObjectMethodInterceptor : IMethodInterceptor - { - #region Logging Definition - - private static readonly ILog LOG = LogManager.GetLogger(typeof(SpringObjectMethodInterceptor)); - - #endregion - - private readonly IConfigurableListableObjectFactory _configurableListableObjectFactory; - - - public SpringObjectMethodInterceptor(IConfigurableListableObjectFactory configurableListableObjectFactory) - { - _configurableListableObjectFactory = configurableListableObjectFactory; - - } - - #region IMethodInterceptor Members - - public object Invoke(IMethodInvocation invocation) - { - MethodInfo m = invocation.Method; - if (m.Name.StartsWith("set_") || m.Name.StartsWith("get_")) - return invocation.Proceed(); - - string name = m.Name; - - object[] attribs = m.GetCustomAttributes(typeof(DefinitionAttribute), true); - if (attribs.Length > 0) - { - - } - - - if (IsCurrentlyInCreation(name)) - { - if (LOG.IsDebugEnabled) - { - LOG.Debug(name + " currently in creation, created one."); - } - return invocation.Proceed(); - } - if (LOG.IsDebugEnabled) - { - LOG.Debug(name + " not in creation, asked the application context for one"); - } - - return _configurableListableObjectFactory.GetObject(name); - } - - private bool IsCurrentlyInCreation(string name) - { - return _configurableListableObjectFactory.IsCurrentlyInCreation(name); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyObjectDefinitionScanner.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyObjectDefinitionScanner.cs deleted file mode 100644 index 42b9fed5..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyObjectDefinitionScanner.cs +++ /dev/null @@ -1,258 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Reflection; -using System.IO; -using Common.Logging; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - - public interface IAssemblyTypeScanner - { - IAssemblyTypeScanner AssemblyHavingType(); - IAssemblyTypeScanner WithAssemblyFilter(Predicate assemblyPredicate); - - IAssemblyTypeScanner WithIncludeFilter(Predicate predicate); - IAssemblyTypeScanner WithExcludeFilter(Predicate predicate); - - IAssemblyTypeScanner IncludeTypes(IEnumerable typeSource); - IAssemblyTypeScanner IncludeType(); - IAssemblyTypeScanner ExcludeType(); - - IEnumerable Scan(); - } - - public abstract class AssemblyTypeScanner : IAssemblyTypeScanner - { - protected readonly List> _assemblyPredicates = new List>(); - - protected readonly List> _excludePredicates = new List>(); - - protected string _folderScanPath; - - protected readonly List> _includePredicates = new List>(); - - protected static ILog _logger = LogManager.GetLogger(typeof(AssemblyTypeScanner)); - - protected readonly List> _typeSources = new List>(); - - /// - /// Initializes a new instance of the AssemblyTypeScanner class. - /// - /// - public AssemblyTypeScanner(string folderScanPath) - { - if (!string.IsNullOrEmpty(folderScanPath)) - { - _folderScanPath = folderScanPath; - } - else - { - _folderScanPath = GetCurrentBinDirectoryPath(); - } - } - - /// - /// Initializes a new instance of the AssemblyTypeScanner class. - /// - public AssemblyTypeScanner() - { - - } - - public IAssemblyTypeScanner AssemblyHavingType() - { - _typeSources.Add(new AssemblyTypeSource((typeof(T).Assembly))); - return this; - } - - public IAssemblyTypeScanner ExcludeType() - { - _excludePredicates.Add(t => t == typeof(T)); - return this; - } - - public IAssemblyTypeScanner IncludeType() - { - _includePredicates.Add(t => t == typeof(T)); - return this; - } - - public IAssemblyTypeScanner IncludeTypes(IEnumerable typeSource) - { - AssertUtils.ArgumentNotNull(typeSource, "typeSource"); - _typeSources.Add(typeSource); - _includePredicates.Add(t => typeSource.Any(t1 => t1 == t)); - return this; - } - - public virtual IEnumerable Scan() - { - SetDefaultFilters(); - - IList types = new List(); - - foreach (Assembly assembly in GetAllMatchingAssemblies()) - { - _typeSources.Add(new AssemblyTypeSource(assembly)); - } - - foreach (var typeSource in _typeSources) - { - foreach (Type type in typeSource) - { - if (IsIncludedType(type) && !IsExcludedType(type) && FinalVetoConstraintIsSatisfiedBy(type)) - { - types.Add(type); - } - } - } - - return types; - } - - public IAssemblyTypeScanner WithAssemblyFilter(Predicate assemblyPredicate) - { - _assemblyPredicates.Add(assemblyPredicate); - return this; - } - - public IAssemblyTypeScanner WithExcludeFilter(Predicate predicate) - { - _excludePredicates.Add(predicate); - return this; - } - - public IAssemblyTypeScanner WithIncludeFilter(Predicate predicate) - { - _includePredicates.Add(predicate); - return this; - } - - protected virtual bool IsExcludedType(Type type) - { - foreach (var exclude in _excludePredicates) - { - if (exclude(type)) - { - return true; - } - } - return false; - } - - protected virtual bool IsIncludedAssembly(Assembly assembly) - { - foreach (var include in _assemblyPredicates) - { - if (include(assembly)) - { - return true; - } - } - return false; - } - - protected virtual bool IsIncludedType(Type type) - { - foreach (var include in _includePredicates) - { - if (include(type)) - { - return true; - } - } - return false; - } - - protected virtual void SetDefaultFilters() - { - if (_includePredicates.Count == 0) - _includePredicates.Add(t => true); - - if (_excludePredicates.Count == 0) - _excludePredicates.Add(t => false); - - if (_assemblyPredicates.Count == 0) - _assemblyPredicates.Add(a => true); - } - - protected virtual bool FinalVetoConstraintIsSatisfiedBy(Type type) - { - return true; - } - - private IEnumerable ApplyAssemblyFiltersTo(IEnumerable assemblyCandidates) - { - IList matchingAssemblies = new List(); - foreach (Assembly assemblyCandidate in assemblyCandidates) - if (IsIncludedAssembly(assemblyCandidate)) - matchingAssemblies.Add(assemblyCandidate); - return matchingAssemblies; - } - - private IEnumerable GetAllAssembliesInPath(string folderPath) - { - IList assemblies = new List(); - IEnumerable files = Directory.GetFiles(folderPath, "*.dll"); - foreach (string file in files) - try - { - assemblies.Add(Assembly.LoadFrom(file)); - } - catch (Exception ex) - { - //log and swallow everything that might go wrong here... - if (_logger.IsDebugEnabled) - _logger.Debug("Failed to load type while scanning Assemblies for Defintions!", ex); - } - return assemblies; - } - - private IEnumerable GetAllMatchingAssemblies() - { - IEnumerable assemblyCandidates = GetAllAssembliesInPath(_folderScanPath); - return ApplyAssemblyFiltersTo(assemblyCandidates); - } - - private string GetCurrentBinDirectoryPath() - { - return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - } - - } - - public class AssemblyObjectDefinitionScanner : AssemblyTypeScanner - { - /// - /// Initializes a new instance of the AssemblyObjectDefinitionScanner class. - /// - /// The folder scan path. - public AssemblyObjectDefinitionScanner(string folderScanPath) - : base(folderScanPath) - { } - - /// - /// Initializes a new instance of the AssemblyObjectDefinitionScanner class. - /// - public AssemblyObjectDefinitionScanner() - : base(null) - { } - - //protected override bool RequiredConstraintIsSatisfiedBy(Type type) - //{ - // return Attribute.GetCustomAttribute(type, typeof(ConfigurationAttribute), true) != null; - //} - - protected override void SetDefaultFilters() - { - _includePredicates.Add(t => Attribute.GetCustomAttribute(t, typeof(ConfigurationAttribute), true) != null); - - base.SetDefaultFilters(); - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyTypeSource.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyTypeSource.cs deleted file mode 100644 index 588f28fb..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/AssemblyTypeSource.cs +++ /dev/null @@ -1,51 +0,0 @@ -#region License - -/* - * Copyright © 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 - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.InteropServices; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - public class AssemblyTypeSource : IEnumerable - { - private readonly _Assembly assembly; - - public AssemblyTypeSource(Assembly assembly) - { - AssertUtils.ArgumentNotNull(assembly, "assembly"); - this.assembly = assembly; - } - - public IEnumerator GetEnumerator() - { - foreach (var type in assembly.GetTypes()) - yield return type; - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} \ No newline at end of file diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationAttribute.cs deleted file mode 100644 index 348d2e28..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationAttribute.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Stereotype; - -namespace Spring.Context.Attributes -{ - /// - /// Indicates that a class declares one or more methods and may be processed - /// by the Spring container to generate object definitions and service requests for those objects - /// at runtime. - /// - /// Configuration is meta-annotated as a {@link Component}, therefore Configuration - /// classes are candidates for component-scanning and may also take advantage of - /// at the field and method but not at the constructor level. - /// - /// May be used in conjunction with the attribute to indicate that all object - /// methods declared within this class are by default lazily initialized. - /// - ///

Constraints

- ///
    - ///
  • Configuration classes must be non-final
  • - ///
  • Configuration classes must be non-local (may not be declared within a method)
  • - ///
  • Configuration classes must have a default/no-arg constructor and may not use - /// {@link Autowired} constructor parameters
  • - ///
- ///
- [AttributeUsage(AttributeTargets.Class)] - public class ConfigurationAttribute : ComponentAttribute - { - - /// - /// Initializes a new instance of the ConfigurationAttribute class. - /// - public ConfigurationAttribute() - { - - } - - private string _name; - - /// - /// Initializes a new instance of the Configuration class. - /// - /// - public ConfigurationAttribute(string name) - { - _name = name; - } - - /// - /// Explicitly specify the name of the Spring object definition associated - /// with this Configuration class. If left unspecified (the common case), - /// a object name will be automatically generated. - /// - /// The custom name applies only if the Configuration class is picked up via - /// component scanning or supplied directly to a . - /// If the Configuration class is registered as a traditional XML object definition, - /// the name/id of the object element will take precedence. - /// - /// - /// - /// The name. - public string Name - { - get { return _name; } - set - { - _name = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClass.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClass.cs deleted file mode 100644 index 3f0cade0..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClass.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Core.IO; -using Spring.Collections.Generic; -using Spring.Objects.Factory.Parsing; - -namespace Spring.Context.Attributes -{ - public class ConfigurationClass - { - private Type _configurationClassType; - - private IDictionary _importedResources = new Dictionary(); - - private ISet _methods = new HashedSet(); - - private string _objectName; - - private IResource _resource; - - /// - /// Initializes a new instance of the ConfigurationClass class. - /// - /// - /// - public ConfigurationClass(string objectName, Type type) - { - this._objectName = objectName; - this._configurationClassType = type; - } - - public Type ConfigurationClassType - { - get - { - return _configurationClassType; - } - } - - public IDictionary ImportedResources - { - get - { - return _importedResources; - } - } - - public ISet Methods - { - get - { - return _methods; - } - } - - public string ObjectName - { - get - { - return _objectName; - } - set - { - _objectName = value; - } - } - - public IResource Resource - { - get - { - return _resource; - } - } - - public string SimpleName - { - get { return ConfigurationClassType.Name; } - } - - public void AddImportedResource(string importedResource, Type readerClass) - { - _importedResources.Add(importedResource, readerClass); - } - - public override bool Equals(object other) - { - return this == other || (other is ConfigurationClass && ConfigurationClassType.Name.Equals(((ConfigurationClass)other).ConfigurationClassType.Name)); - } - - public override int GetHashCode() - { - return ConfigurationClassType.Name.GetHashCode() * 14; - } - - public void Validate(IProblemReporter problemReporter) - { - // A [Definition] method may only be overloaded through inheritance. No single - // [Configuration] class may declare two [Definition] methods with the same name. - char hashDelim = '#'; - Dictionary methodNameCounts = new Dictionary(); - foreach (ConfigurationClassMethod method in _methods) - { - String dClassName = method.MethodMetadata.DeclaringType.FullName; - String methodName = method.MethodMetadata.Name; - String fqMethodName = dClassName + hashDelim + methodName; - if (!methodNameCounts.ContainsKey(fqMethodName)) - { - methodNameCounts.Add(fqMethodName, 1); - } - else - { - int currentCount = methodNameCounts[fqMethodName]; - methodNameCounts.Add(fqMethodName, currentCount++); - } - } - - foreach (String methodName in methodNameCounts.Keys) - { - int count = methodNameCounts[methodName]; - if (count > 1) - { - String shortMethodName = methodName.Substring(methodName.IndexOf(hashDelim) + 1); - problemReporter.Error(new ObjectMethodOverloadingProblem(shortMethodName, count, Resource, ConfigurationClassType)); - } - } - - if (Attribute.GetCustomAttribute(_configurationClassType, typeof(ConfigurationAttribute)) != null) - { - - if (ConfigurationClassType.IsSealed) - { - problemReporter.Error(new SealedConfigurationProblem(SimpleName, Resource, ConfigurationClassType)); - - } - - foreach (ConfigurationClassMethod method in _methods) - { - method.Validate(problemReporter); - } - } - } - - private class SealedConfigurationProblem : Problem - { - public SealedConfigurationProblem(string name, IResource resource, Type configurationClassType) - : base(String.Format("[Configuration] class '{0}' may not be sealed. Remove the sealed modifier to continue.", name), new Location(resource, configurationClassType)) - { } - - } - - private class ObjectMethodOverloadingProblem : Problem - { - public ObjectMethodOverloadingProblem(string methodName, int count, IResource resource, Type configurationClassType) - : base(String.Format("[Configuration] class '{0}' has {1} overloaded [Definiton] methods named '{2}'. " + - "Only one [Definition] method of a given name is allowed within each [Configuration] class.", configurationClassType.Name, count, methodName), new Location(resource, configurationClassType)) - { } - - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassMethod.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassMethod.cs deleted file mode 100644 index ecb49b02..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassMethod.cs +++ /dev/null @@ -1,123 +0,0 @@ -#region License - -/* - * Copyright © 2002-2010 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.Collections.Generic; -using System; -using System.Text; -using Spring.Core.IO; -using System.Reflection; -using Spring.Objects.Factory.Parsing; - -namespace Spring.Context.Attributes -{ - - /** - * Represents a {@link Configuration} class method marked with the {@link Object} annotation. - * - * @author Chris Beams - * @author Juergen Hoeller - * @since 3.0 - * @see ConfigurationClass - * @see ConfigurationClassParser - * @see ConfigurationClassObjectDefinitionReader - */ - - public class ConfigurationClassMethod - { - private ConfigurationClass _configurationClass; - - private MethodInfo _methodInfo; - - /// - /// Initializes a new instance of the ConfigurationClassMethod class. - /// - /// - /// - public ConfigurationClassMethod(MethodInfo methodInfo, ConfigurationClass configurationClass) - { - _methodInfo = methodInfo; - _configurationClass = configurationClass; - } - - public ConfigurationClass ConfigurationClass - { - get - { - return _configurationClass; - } - } - - public MethodInfo MethodMetadata - { - get - { - return _methodInfo; - } - } - - public Location ResourceLocation - { - get { return new Location(_configurationClass.Resource, _methodInfo); } - - } - - public override string ToString() - { - return string.Format("{0}:name={1},declaringClass={2}", this.GetType().Name, _methodInfo.Name, _methodInfo.DeclaringType.FullName); - } - - public void Validate(IProblemReporter problemReporter) - { - //TODO: shouldn't this be "if method has Definition attribute" instead of "if class has Configuration attribute" --???? - if (Attribute.GetCustomAttribute(ConfigurationClass.ConfigurationClassType, typeof(ConfigurationAttribute)) != null) - { - if (!MethodMetadata.IsVirtual) - { - problemReporter.Error(new NonVirtualMethodError(MethodMetadata.Name, ResourceLocation)); - } - } - - else - { - if (MethodMetadata.IsStatic) - { - problemReporter.Error(new StaticMethodError(MethodMetadata.Name, ResourceLocation)); - } - } - } - - private class StaticMethodError : Problem - { - public StaticMethodError(string methodName, Location location) - : base(String.Format("Method '{0}' must not be static; remove the method's static modifier to continue", - methodName), location) - { } - } - - private class NonVirtualMethodError : Problem - { - public NonVirtualMethodError(string methodName, Location location) - : base(String.Format("Method '{0}' must be public virtual; change the method's modifiers to continue", - methodName), location) - { } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassObjectDefinitionReader.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassObjectDefinitionReader.cs deleted file mode 100644 index df7517b5..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassObjectDefinitionReader.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Support; -using Spring.Objects.Factory.Parsing; -using Spring.Collections.Generic; -using System.Reflection; -using Spring.Objects.Factory.Config; -using Common.Logging; -using Spring.Objects; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - public class ConfigurationClassObjectDefinitionReader - { - private readonly ILog _logger = LogManager.GetLogger(typeof(ConfigurationClassObjectDefinitionReader)); - - private IProblemReporter _problemReporter; - - private IObjectDefinitionRegistry _registry; - - /// - /// Initializes a new instance of the ConfigurationClassObjectDefinitionReader class. - /// - /// - /// - public ConfigurationClassObjectDefinitionReader(IObjectDefinitionRegistry registry, IProblemReporter problemReporter) - { - _registry = registry; - _problemReporter = problemReporter; - } - - public static bool CheckConfigurationClassCandidate(Type type) - { - if (type != null) - { - return (Attribute.GetCustomAttribute(type, typeof(ConfigurationAttribute)) != null); - } - - return false; - } - - public void LoadObjectDefinitions(ISet configurationModel) - { - foreach (ConfigurationClass configClass in configurationModel) - { - LoadObjectDefinitionsForConfigurationClass(configClass); - } - } - - private void LoadObjectDefinitionForConfigurationClassIfNecessary(ConfigurationClass configClass) - { - if (configClass.ObjectName != null) - { - // a Object definition already exists for this configuration class -> nothing to do - return; - } - - // no Object definition exists yet -> this must be an imported configuration class (@Import). - GenericObjectDefinition configObjectDef = new GenericObjectDefinition(); - String className = configClass.ConfigurationClassType.Name; - configObjectDef.ObjectType = configClass.ConfigurationClassType; - if (CheckConfigurationClassCandidate(configClass.ConfigurationClassType)) - { - String configObjectName = ObjectDefinitionReaderUtils.RegisterWithGeneratedName(configObjectDef, _registry); - configClass.ObjectName = configObjectName; - if (_logger.IsDebugEnabled) - { - _logger.Debug(String.Format("Registered object definition for imported [Configuration] class {0}", configObjectName)); - } - } - } - - private void LoadObjectDefinitionsForConfigurationClass(ConfigurationClass configClass) - { - LoadObjectDefinitionForConfigurationClassIfNecessary(configClass); - - foreach (ConfigurationClassMethod method in configClass.Methods) - { - LoadObjectDefinitionsForModelMethod(method); - } - - LoadObjectDefinitionsFromImportedResources(configClass.ImportedResources); - } - - private void LoadObjectDefinitionsForModelMethod(ConfigurationClassMethod method) - { - ConfigurationClass configClass = method.ConfigurationClass; - MethodInfo metadata = method.MethodMetadata; - - RootObjectDefinition objDef = new ConfigurationClassObjectDefinition(); - //ObjectDef.Resource = configClass.Resource; - //ObjectDef.setSource(this.sourceExtractor.extractSource(metadata, configClass.getResource())); - - - - objDef.FactoryObjectName = configClass.ObjectName; - objDef.FactoryMethodName = metadata.Name; - objDef.AutowireMode = Objects.Factory.Config.AutoWiringMode.Constructor; - - //ObjectDef.setAttribute(RequiredAnnotationObjectPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE); - - // consider name and any aliases - //Dictionary ObjectAttributes = metadata.getAnnotationAttributes(Object.class.getName()); - object[] objectAttributes = metadata.GetCustomAttributes(typeof(DefinitionAttribute), true); - List names = new List(); - for (int i = 0; i < objectAttributes.Length; i++) - { - string[] namesAndAliases = ((DefinitionAttribute)objectAttributes[i]).NamesToArray; - - if (namesAndAliases != null) - { - names.Add(metadata.Name); - } - else - { - namesAndAliases = new[] { metadata.Name }; - } - - for (int j = 0; j < namesAndAliases.Length; j++) - { - names.Add(namesAndAliases[j]); - } - } - - string objectName = (names.Count > 0 ? names[0] : method.MethodMetadata.Name); - for (int i = 1; i < names.Count; i++) - { - _registry.RegisterAlias(objectName, names[i]); - } - - // has this already been overridden (e.g. via XML)? - if (_registry.ContainsObjectDefinition(objectName)) - { - IObjectDefinition existingObjectDef = _registry.GetObjectDefinition(objectName); - // is the existing Object definition one that was created from a configuration class? - if (!(existingObjectDef is ConfigurationClassObjectDefinition)) - { - // no -> then it's an external override, probably XML - // overriding is legal, return immediately - if (_logger.IsDebugEnabled) - { - _logger.Debug(String.Format("Skipping loading Object definition for {0}: a definition for object " + - "'{1}' already exists. This is likely due to an override in XML.", method, objectName)); - } - return; - } - } - - if (Attribute.GetCustomAttribute(metadata, typeof(PrimaryAttribute)) != null) - { - //TODO: determine how to respond to this attribute's presence - //ObjectDef.isPrimary = true; - } - - // is this Object to be instantiated lazily? - if (Attribute.GetCustomAttribute(metadata, typeof(LazyAttribute)) != null) - { - objDef.IsLazyInit = (Attribute.GetCustomAttribute(metadata, typeof(LazyAttribute)) as LazyAttribute).LazyInitialize; - } - - if (Attribute.GetCustomAttribute(metadata, typeof(DependsOnAttribute)) != null) - { - objDef.DependsOn = (Attribute.GetCustomAttribute(metadata, typeof(DependsOnAttribute)) as DependsOnAttribute).Name; - } - - //Autowire autowire = (Autowire) ObjectAttributes.get("autowire"); - //if (autowire.isAutowire()) { - // ObjectDef.setAutowireMode(autowire.value()); - //} - - if (Attribute.GetCustomAttribute(metadata, typeof(DefinitionAttribute)) != null) - { - objDef.InitMethodName = (Attribute.GetCustomAttribute(metadata, typeof(DefinitionAttribute)) as DefinitionAttribute).InitMethod; - objDef.DestroyMethodName = (Attribute.GetCustomAttribute(metadata, typeof(DefinitionAttribute)) as DefinitionAttribute).DestroyMethod; - } - - // consider scoping - if (Attribute.GetCustomAttribute(metadata, typeof(ScopeAttribute)) != null) - { - objDef.Scope = (Attribute.GetCustomAttribute(metadata, typeof(ScopeAttribute)) as ScopeAttribute).ObjectScope.ToString(); - } - - if (_logger.IsDebugEnabled) - { - _logger.Debug(String.Format("Registering Object definition for [Definition] method {0}.{1}()", configClass.ConfigurationClassType.Name, objectName)); - } - - _registry.RegisterObjectDefinition(objectName, objDef); - } - - private void LoadObjectDefinitionsFromImportedResources(IDictionary importedResources) - { - IDictionary readerInstanceCache = new Dictionary(); - foreach (KeyValuePair entry in importedResources) - { - String resource = entry.Key; - Type readerClass = entry.Value; - - if (!readerInstanceCache.ContainsKey(readerClass)) - { - try - { - IObjectDefinitionReader readerInstance = - (IObjectDefinitionReader)Activator.CreateInstance(readerClass, _registry); - - readerInstanceCache.Add(readerClass, readerInstance); - } - catch (Exception) - { - throw new InvalidOperationException(String.Format("Could not instantiate IObjectDefinitionReader class {0}", readerClass.FullName)); - } - } - - IObjectDefinitionReader reader = readerInstanceCache[readerClass]; - - reader.LoadObjectDefinitions(resource); - } - } - - private class ConfigurationClassObjectDefinition : RootObjectDefinition - { - - } - - } - -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassParser.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassParser.cs deleted file mode 100644 index c6091d96..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassParser.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Parsing; -using Spring.Collections.Generic; -using Spring.Util; -using System.Reflection; - -namespace Spring.Context.Attributes -{ - - public class ConfigurationClassParser - { - private ISet _configurationClasses = new HashedSet(); - - private Stack _importStack = new Stack(); - - private IProblemReporter _problemReporter; - - /// - /// Initializes a new instance of the ConfigurationClassParser class. - /// - /// - public ConfigurationClassParser(IProblemReporter problemReporter) - { - _problemReporter = problemReporter; - } - - public ISet ConfigurationClasses - { - get { return _configurationClasses; } - } - - //public void Parse(String className, String ObjectName) - //{ - // ProcessConfigurationClass(new ConfigurationClass(className, ObjectName)); - //} - - public void Parse(Type type, string objectName) - { - ProcessConfigurationClass(new ConfigurationClass(objectName, type)); - } - - public void Validate() - { - foreach (ConfigurationClass configClass in ConfigurationClasses) - { - configClass.Validate(_problemReporter); - } - } - - protected void ProcessConfigurationClass(ConfigurationClass configurationClass) - { - DoProcessConfigurationClass(configurationClass); - - if (ConfigurationClasses.Contains(configurationClass) && configurationClass.ObjectName != null) - { - // Explicit object definition found, probably replacing an import. - // Let's remove the old one and go with the new one. - ConfigurationClasses.Remove(configurationClass); - } - ConfigurationClasses.Add(configurationClass); - } - - private void DoProcessConfigurationClass(ConfigurationClass configurationClass) - { - if (Attribute.GetCustomAttribute(configurationClass.ConfigurationClassType, typeof(ImportAttribute)) != null) - { - ImportAttribute attrib = Attribute.GetCustomAttribute(configurationClass.ConfigurationClassType, typeof(ImportAttribute)) as ImportAttribute; - ProcessImport(configurationClass, attrib.Types); - } - - if (Attribute.GetCustomAttribute(configurationClass.ConfigurationClassType, typeof(ImportResourceAttribute)) != null) - { - ImportResourceAttribute attrib = Attribute.GetCustomAttribute(configurationClass.ConfigurationClassType, typeof(ImportResourceAttribute)) as ImportResourceAttribute; - - foreach (string resource in attrib.Resources) - { - configurationClass.AddImportedResource(resource, attrib.DefinitionReader); - } - } - - ISet definitionMethods = GetAllMethodsWithCustomAttributeForClass(configurationClass.ConfigurationClassType, typeof(DefinitionAttribute)); - foreach (MethodInfo definitionMethod in definitionMethods) - { - configurationClass.Methods.Add(new ConfigurationClassMethod(definitionMethod, configurationClass)); - - } - } - - private ISet GetAllMethodsWithCustomAttributeForClass(Type theClass, Type customAttribute) - { - ISet methods = new HashedSet(); - - foreach (MethodInfo method in theClass.GetMethods()) - { - if (Attribute.GetCustomAttribute(method, customAttribute) != null) - { - methods.Add(method); - } - } - - return methods; - } - - private void ProcessImport(ConfigurationClass configClass, Type[] classesToImport) - { - if (_importStack.Contains(configClass)) - { - _problemReporter.Error(new CircularImportProblem(configClass, _importStack, configClass.ConfigurationClassType)); - } - else - { - _importStack.Push(configClass); - foreach (Type classToImport in classesToImport) - { - ProcessConfigurationClass(new ConfigurationClass(null, classToImport)); - } - _importStack.Pop(); - } - } - - private class CircularImportProblem : Problem - { - public CircularImportProblem(ConfigurationClass configClass, Stack importStack, Type configurationClassType) - : base(String.Format("A circular @Import has been detected: " + - "Illegal attempt by [Configuration] class '{0}' to import class '{1}' as '{2}' is " + - "already present in the current import stack [{3}]", - importStack.Peek().SimpleName, configClass.SimpleName, - configClass.SimpleName, importStack), - new Location(importStack.Peek().Resource, configurationClassType) - ) - { } - - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassPostProcessor.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassPostProcessor.cs deleted file mode 100644 index 54210c4a..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ConfigurationClassPostProcessor.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Common.Logging; -using Spring.Objects.Factory.Parsing; -using Spring.Objects.Factory.Support; -using Spring.Objects.Factory.Config; -using Spring.Collections.Generic; -using Spring.Objects.Factory; -using Spring.Core; -using Spring.Aop.Framework; -using Spring.Context.Advice; -using Spring.Aop.Framework.DynamicProxy; -using Spring.Aop; - -namespace Spring.Context.Attributes -{ - public class ConfigurationClassPostProcessor : IObjectDefinitionRegistryPostProcessor, IOrdered - { - private ILog _logger = LogManager.GetLogger(typeof(ConfigurationClassPostProcessor)); - - private bool _postProcessObjectDefinitionRegistryCalled = false; - - private bool _postProcessObjectFactoryCalled = false; - - private IProblemReporter _problemReporter = new FailFastProblemReporter(); - - public int Order - { - get { return int.MinValue; } - } - - public IProblemReporter ProblemReporter - { - set { _problemReporter = (value ?? new FailFastProblemReporter()); } - } - - public void PostProcessObjectDefinitionRegistry(IObjectDefinitionRegistry registry) - { - if (_postProcessObjectDefinitionRegistryCalled) - { - throw new InvalidOperationException("PostProcessObjectDefinitionRegistry already called for this post-processor"); - } - if (_postProcessObjectFactoryCalled) - { - throw new InvalidOperationException("PostProcessObjectFactory already called for this post-processor"); - } - _postProcessObjectDefinitionRegistryCalled = true; - ProcessConfigObjectDefinitions(registry); - } - - public void PostProcessObjectFactory(IConfigurableListableObjectFactory objectFactory) - { - if (_postProcessObjectFactoryCalled) - { - throw new InvalidOperationException( - "PostProcessObjectFactory already called for this post-processor"); - } - _postProcessObjectFactoryCalled = true; - if (!_postProcessObjectDefinitionRegistryCalled) - { - // ObjectDefinitionRegistryPostProcessor hook apparently not supported... - // Simply call processConfigObjectDefinitions lazily at this point then. - ProcessConfigObjectDefinitions((IObjectDefinitionRegistry)objectFactory); - } - - EnhanceConfigurationClasses(objectFactory); - } - - private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory) - { - string[] objectNames = objectFactory.GetObjectDefinitionNames(); - - for (int i = 0; i < objectNames.Length; i++) - { - IObjectDefinition objDef = objectFactory.GetObjectDefinition(objectNames[i]); - - if (((AbstractObjectDefinition)objDef).HasObjectType) - { - if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null) - { - - ProxyFactory proxyFactory = new ProxyFactory(); - proxyFactory.ProxyTargetAttributes = true; - proxyFactory.Interfaces = Type.EmptyTypes; - proxyFactory.TargetSource = new ObjectFactoryTargetSource(objectNames[i], objectFactory); - SpringObjectMethodInterceptor methodInterceptor = new SpringObjectMethodInterceptor(objectFactory); - proxyFactory.AddAdvice(methodInterceptor); - - //TODO check type of object isn't infrastructure type. - - InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(proxyFactory); - //iaptb.ProxyDeclaredMembersOnly = true; // make configurable. - ((IConfigurableObjectDefinition)objDef).ObjectType = iaptb.BuildProxyType(); - - objDef.ConstructorArgumentValues.AddIndexedArgumentValue(objDef.ConstructorArgumentValues.ArgumentCount, proxyFactory); - - } - } - - } - - } - - private Type GenerateProxyType(string objectName, IConfigurableListableObjectFactory objectFactory) - { - ProxyFactory proxyFactory = new ProxyFactory(); - proxyFactory.ProxyTargetAttributes = true; - proxyFactory.Interfaces = Type.EmptyTypes; - proxyFactory.TargetSource = new ObjectFactoryTargetSource(objectName, objectFactory); - SpringObjectMethodInterceptor methodInterceptor = new SpringObjectMethodInterceptor(objectFactory); - proxyFactory.AddAdvice(methodInterceptor); - - //TODO check type of object isn't infrastructure type. - - InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(proxyFactory); - //iaptb.ProxyDeclaredMembersOnly = true; // make configurable. - return iaptb.BuildProxyType(); - } - - private void ProcessConfigObjectDefinitions(IObjectDefinitionRegistry registry) - { - ISet configCandidates = new HashedSet(); - foreach (string objectName in registry.GetObjectDefinitionNames()) - { - IObjectDefinition objectDef = registry.GetObjectDefinition(objectName); - if (ConfigurationClassObjectDefinitionReader.CheckConfigurationClassCandidate(objectDef.ObjectType)) - { - configCandidates.Add(new ObjectDefinitionHolder(objectDef, objectName)); - } - } - - //if nothing to process, bail out - if (configCandidates.Count == 0) { return; } - - ConfigurationClassParser parser = new ConfigurationClassParser(_problemReporter); - foreach (ObjectDefinitionHolder holder in configCandidates) - { - IObjectDefinition bd = holder.ObjectDefinition; - try - { - if (bd is AbstractObjectDefinition && ((AbstractObjectDefinition)bd).HasObjectType) - { - parser.Parse(((AbstractObjectDefinition)bd).ObjectType, holder.ObjectName); - } - else - { - //parser.Parse(bd.ObjectTypeName, holder.ObjectName); - } - } - catch (ObjectDefinitionParsingException ex) - { - throw new ObjectDefinitionStoreException("Failed to load object class: " + bd.ObjectTypeName, ex); - } - } - parser.Validate(); - - // Read the model and create Object definitions based on its content - ConfigurationClassObjectDefinitionReader reader = new ConfigurationClassObjectDefinitionReader(registry, _problemReporter); - reader.LoadObjectDefinitions(parser.ConfigurationClasses); - } - - public class ObjectFactoryTargetSource : ITargetSource - { - private readonly string _objectName; - private readonly IConfigurableListableObjectFactory _objectFactory; - - public ObjectFactoryTargetSource(string objectName, IConfigurableListableObjectFactory objectFactory) - { - _objectName = objectName; - _objectFactory = objectFactory; - } - - #region ITargetSource Members - - public object GetTarget() - { - return _objectFactory.GetObject(_objectName); - } - - public bool IsStatic - { - get { return _objectFactory.IsSingleton(_objectName); } - } - - public void ReleaseTarget(object target) - { - } - - public Type TargetType - { - get { return _objectFactory.GetType(_objectName); } - } - - #endregion - } - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/DefinitionAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/DefinitionAttribute.cs deleted file mode 100644 index 93086cec..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/DefinitionAttribute.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Config; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - [AttributeUsage(AttributeTargets.Method)] - public class DefinitionAttribute : Attribute - { - private AutoWiringMode _autoWire = AutoWiringMode.No; - - private string _destroyMethod; - - private string _initMethod; - - private string _names; - - /// - /// Are dependencies to be injected via autowiring? - /// - /// The auto wire. - public AutoWiringMode AutoWire - { - get { return _autoWire; } - set - { - _autoWire = value; - } - } - - /// - /// The optional name of a method to call on the Object instance upon closing the - /// application context, for example a Close() method on a DataSource. - /// The method must have no arguments but may throw any exception. - /// - /// Note: Only invoked on objects whose lifecycle is under the full control of the - /// factory, which is always the case for singletons but not guaranteed - /// for any other scope. - /// - /// - /// - /// The destroy method. - public string DestroyMethod - { - get { return _destroyMethod; } - set - { - _destroyMethod = value; - } - } - - /// - /// The optional name of a method to call on the object instance during initialization. - /// Not commonly used, given that the method may be called programmatically directly - /// within the body of a Object-annotated method. - /// - /// The init method. - public string InitMethod - { - get { return _initMethod; } - set - { - _initMethod = value; - } - } - - /// - /// The name of this object, or if plural, aliases for this object. If left unspecified - /// the name of the object is the name of the attributed method. If specified, the method - /// name is ignored. - /// - /// The name. - public string Names - { - get - { - return _names; - } - set - { - _names = value; - } - } - - public string[] NamesToArray - { - get - { - return StringUtils.DelimitedListToStringArray(_names, ","); - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/DependsOnAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/DependsOnAttribute.cs deleted file mode 100644 index ff8c220f..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/DependsOnAttribute.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Spring.Context.Attributes -{ - /// - /// objects on which the current object depends. Any objects specified are guaranteed to be - /// created by the container before this object. Used infrequently in cases where a object - /// does not explicitly depend on another through properties or constructor arguments, - /// but rather depends on the side effects of another object's initialization. - /// Note: This attribute will not be inherited by child object definitions, - /// hence it needs to be specified per concrete object definition. - /// - /// Using at the class level has no effect unless component-scanning - /// is being used. If a -attributed class is declared via XML, - /// attribute metadata is ignored, and - /// <object depends-on="..."/> is respected instead. - /// - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] - public class DependsOnAttribute : Attribute - { - private string[] _name; - - /// - /// Initializes a new instance of the DependsOn class. - /// - /// - public DependsOnAttribute(string[] name) - { - _name = name; - } - - public string[] Name - { - get { return _name; } - set - { - _name = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportAttribute.cs deleted file mode 100644 index fa381774..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportAttribute.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Spring.Context.Attributes -{ - /// - /// Indicates one or more classes to import. - /// - /// Provides functionality equivalent to the :lt;import/> element in Spring XML. - /// Only supported for actual -attributed classes. - /// - /// - /// definitions declared in imported classes - /// should be accessed by using injection. Either the object - /// itself can be autowired, or the configuration class instance declaring the object can be - /// autowired. The latter approach allows for explicit, IDE-friendly navigation between - /// class methods. - /// - /// - /// If XML or other non- object definition resources need to be - /// imported, use - /// - /// - [AttributeUsage(AttributeTargets.Class)] - public class ImportAttribute : Attribute - { - private Type[] _types; - - /// - /// Initializes a new instance of the Import class. - /// - /// - public ImportAttribute(Type[] types) - { - _types = types; - } - - /// - /// The class or classes to import. - /// - /// The type. - public Type[] Types - { - get { return _types; } - set - { - _types = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportResourceAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportResourceAttribute.cs deleted file mode 100644 index 241ace48..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ImportResourceAttribute.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Support; -using Spring.Objects.Factory.Xml; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - /// - /// - /// - [AttributeUsage(AttributeTargets.Class)] - public class ImportResourceAttribute : Attribute - { - private Type _objectDefinitionReader = typeof(XmlObjectDefinitionReader); - - private string[] _resources; - - /// - /// Initializes a new instance of the ImportResourceAttribute class. - /// - /// - public ImportResourceAttribute(string[] resources) - { - if (resources ==null || resources.Length ==0) - throw new ArgumentException("resources cannot be null or empty!"); - - _resources = resources; - } - - - /// - /// Initializes a new instance of the ImportResourceAttribute class. - /// - /// - public ImportResourceAttribute(string resource) - { - if (StringUtils.IsNullOrEmpty(resource)) - throw new ArgumentException("resource cannot be null or empty!"); - - _resources = new[] { resource }; - } - - /// - /// implementation to use when processing resources specified - /// by the attribute. - /// - /// The . - public Type DefinitionReader - { - get - { - return _objectDefinitionReader; - } - set - { - if (!((typeof(IObjectDefinitionReader).IsAssignableFrom(value)))) - throw new ArgumentException(string.Format("DefinitionReader must be of type IObjectDefinitionReader but was of type {0}", value.Name)); - - _objectDefinitionReader = value; - } - } - - /// - /// Resource paths to import. Resource-loading prefixes such as assembly:// and - /// file://, etc may be used. - /// - /// The resources. - public string[] Resources - { - get { return _resources; } - set - { - _resources = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/LazyAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/LazyAttribute.cs deleted file mode 100644 index 229f4d72..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/LazyAttribute.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Spring.Context.Attributes -{ - /// - /// Indicates whether a object is to be lazily initialized. - /// - /// If this annotation is not present on a Component or object definition, eager - /// initialization will occur. If present and set to true, the - /// object/Component will not be initialized until referenced by another object or - /// explicitly retrieved from the enclosing . - /// If present and set to false, the object will be instantiated on startup by object factories - /// that perform eager initialization of singletons. - /// - /// - /// If Lazy is present on a class, this indicates that all - /// methods within that should be lazily - /// initialized. If Lazy is present and false on a object method within a - /// Lazy-annotated Configuration class, this indicates overriding the 'default - /// lazy' behavior and that the object should be eagerly initialized. - /// - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] - public class LazyAttribute : Attribute - { - private bool _lazyInitialize = true; - - /// - /// Initializes a new instance of the LazyAttribute class. - /// - /// - public LazyAttribute(bool lazyInitialize) - { - _lazyInitialize = lazyInitialize; - } - - /// - /// Initializes a new instance of the LazyAttribute class. - /// - public LazyAttribute() - { - - } - - /// - /// Whether lazy initialization should occur. - /// - /// true if [lazy initialize]; otherwise, false. - public bool LazyInitialize - { - get { return _lazyInitialize; } - set - { - _lazyInitialize = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/PrimaryAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/PrimaryAttribute.cs deleted file mode 100644 index f52187f2..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/PrimaryAttribute.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Spring.Context.Attributes -{ - /// - /// Indicates that an object should be given preference when multiple candidates - /// are qualified to autowire a single-valued dependency. If exactly one 'primary' - /// object exists among the candidates, it will be the autowired value. - /// - /// Using at the class level has no effect unless component-scanning - /// is being used. If a -attributed class is declared via XML, - /// attribute metadata is ignored, and - /// <object primary="true|false"/>> is respected instead. - /// - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - public class PrimaryAttribute : Attribute - { - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Attributes/ScopeAttribute.cs b/src/Spring/Spring.Core.Configuration/Context/Attributes/ScopeAttribute.cs deleted file mode 100644 index 7f0370f7..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Attributes/ScopeAttribute.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Support; - -namespace Spring.Context.Attributes -{ - /// - /// When used as a type-level attribute, indicates the name of a scope to use - /// for instances of the attributed type. - /// - /// When used as a method-level attribute in conjunction with the - /// attribute, indicates the name of a scope to use for - /// the instance returned from the method. - /// - /// In this context, scope means the lifecycle of an instance, such as - /// singleton, prototype, and so forth. - /// - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - public class ScopeAttribute : Attribute - { - private ObjectScope _scope = ObjectScope.Singleton; - - /// - /// Initializes a new instance of the Scope class. - /// - /// - public ScopeAttribute(ObjectScope scope) - { - _scope = scope; - } - - /// - /// Specifies the scope to use for the annotated object. - /// - /// The scope. - public ObjectScope ObjectScope - { - get { return _scope; } - set - { - _scope = value; - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Config/AttributeConfigObjectDefinitionParser.cs b/src/Spring/Spring.Core.Configuration/Context/Config/AttributeConfigObjectDefinitionParser.cs deleted file mode 100644 index 9e79a0e5..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Config/AttributeConfigObjectDefinitionParser.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Xml; -using Spring.Objects.Factory.Support; -using Spring.Util; -using Spring.Context.Attributes; -using Spring.Objects.Factory.Config; - -namespace Spring.Context.Config -{ - public class AttributeConfigObjectDefinitionParser : IObjectDefinitionParser - { - /// - /// The object name of the internally managed configuration attribure processor - /// - public static readonly string CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME = "Spring.Context.Attributes.InternalConfigurationAttributeProcessor"; - - - private static readonly Type ConfigurationClassPostProcessorType = typeof(ConfigurationClassPostProcessor); - - public AttributeConfigObjectDefinitionParser() - { - - } - - public Objects.Factory.Config.IObjectDefinition ParseElement(System.Xml.XmlElement element, ParserContext parserContext) - { - IObjectDefinitionRegistry registry = parserContext.ReaderContext.Registry; - - AssertUtils.ArgumentNotNull(registry, "registry"); - - if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME)) - { - RootObjectDefinition objectDefinition = new RootObjectDefinition(ConfigurationClassPostProcessorType); - objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE; - registry.RegisterObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME, objectDefinition); - } - - return null; - } - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Config/ComponentScanObjectDefinitionParser.cs b/src/Spring/Spring.Core.Configuration/Context/Config/ComponentScanObjectDefinitionParser.cs deleted file mode 100644 index a39f2956..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Config/ComponentScanObjectDefinitionParser.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Xml; - -namespace Spring.Context.Config -{ - public class ComponentScanObjectDefinitionParser - { - public ComponentScanObjectDefinitionParser() - { - - } - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Config/ContextNamespaceParser.cs b/src/Spring/Spring.Core.Configuration/Context/Config/ContextNamespaceParser.cs deleted file mode 100644 index c3be1e11..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Config/ContextNamespaceParser.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Spring.Objects.Factory.Xml; - -namespace Spring.Context.Config -{ - /// - /// NamespaceParser allowing for the configuration of - /// declarative transaction management using either XML or using attributes. - /// - /// This namespace handler is the central piece of functionality in the - /// Spring transaction management facilities and offers two appraoches - /// to declaratively manage transactions. - /// - /// One approach uses transaction semantics defined in XML using the - /// <tx:advice> elements, the other uses attributes - /// in combination with the <tx:annotation-driven> element. - /// Both approached are detailed in the Spring reference manual. - /// - [ - NamespaceParser( - Namespace = "http://www.springframework.net/context", - SchemaLocationAssemblyHint = typeof(ContextNamespaceParser), - SchemaLocation = "/Spring.Context.Config/spring-context-1.3.xsd" - ) - ] - public class ContextNamespaceParser : NamespaceParserSupport - { - /// - /// Register the for the 'advice' and - /// 'attribute-driven' tags. - /// - public override void Init() - { - RegisterObjectDefinitionParser("attribute-config", new AttributeConfigObjectDefinitionParser()); - - //RegisterObjectDefinitionParser("component-scan", new ComponentScanObjectDefinitionParser()); - } - } -} diff --git a/src/Spring/Spring.Core.Configuration/Context/Config/spring-context-1.3.xsd b/src/Spring/Spring.Core.Configuration/Context/Config/spring-context-1.3.xsd deleted file mode 100644 index 87a893f1..00000000 --- a/src/Spring/Spring.Core.Configuration/Context/Config/spring-context-1.3.xsd +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - tag for that purpose. - ]]> - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Spring/Spring.Core.Configuration/Objects/Factory/Support/AssemblyScanningExtensionMethods.cs b/src/Spring/Spring.Core.Configuration/Objects/Factory/Support/AssemblyScanningExtensionMethods.cs deleted file mode 100644 index bcaf6fbf..00000000 --- a/src/Spring/Spring.Core.Configuration/Objects/Factory/Support/AssemblyScanningExtensionMethods.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Reflection; -using System.Linq; -using System.IO; -using Common.Logging; -using Spring.Context.Attributes; - -namespace Spring.Objects.Factory.Support -{ - public static class AssemblyScanningExtensionMethods - { - public static void Scan(this IObjectDefinitionRegistry registry, IAssemblyTypeScanner scanner) - { - IEnumerable configTypes = scanner.Scan(); - - //if we have at least one config class, ensure the post-processor is registered - if (configTypes.Count() > 0) - { - EnsureConfigurationClassPostProcessorIsRegisteredFor(registry); - } - - RegisiterDefintionsForTypes(configTypes, registry); - } - - public static void Scan(this IObjectDefinitionRegistry registry) - { - Scan(registry, new AssemblyObjectDefinitionScanner()); - } - - public static void Scan(this IObjectDefinitionRegistry registry, Predicate typePredicate) - { - Scan(registry, null, ta => true, typePredicate); - } - - public static void Scan(this IObjectDefinitionRegistry registry, string assemblyScanPath, Predicate assemblyPredicate, Predicate typePredicate) - { - //create a scanner instance using the scan path - IAssemblyTypeScanner scanner = new AssemblyObjectDefinitionScanner(assemblyScanPath); - - //configure the scanner per the provided constraints - scanner.WithAssemblyFilter(assemblyPredicate).WithIncludeFilter(typePredicate); - - //pass the scanner to primary Scan method to actually do the work - Scan(registry, scanner); - } - - public static void Scan(this IObjectDefinitionRegistry registry, Predicate assemblyPredicate, Predicate typePredicate) - { - Scan(registry, null, assemblyPredicate, typePredicate); - } - - public static void Scan(this IObjectDefinitionRegistry registry, Predicate assemblyPredicate) - { - Scan(registry, null, assemblyPredicate, t => true); - } - - /// - /// Ensures the configuration class post processor is registered for. - /// - /// The registry. - private static void EnsureConfigurationClassPostProcessorIsRegisteredFor(IObjectDefinitionRegistry registry) - { - var postProcessorBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(ConfigurationClassPostProcessor)); - if (!registry.ContainsObjectDefinition(postProcessorBuilder.ObjectDefinition.ObjectTypeName)) - { - registry.RegisterObjectDefinition(postProcessorBuilder.ObjectDefinition.ObjectTypeName, postProcessorBuilder.ObjectDefinition); - } - } - - /// - /// Regisiters the defintions for types. - /// - /// The types to register. - /// The registry. - private static void RegisiterDefintionsForTypes(IEnumerable typesToRegister, IObjectDefinitionRegistry registry) - { - foreach (Type type in typesToRegister) - { - ObjectDefinitionBuilder definition = ObjectDefinitionBuilder.GenericObjectDefinition(type); - registry.RegisterObjectDefinition(definition.ObjectDefinition.ObjectTypeName, definition.ObjectDefinition); - } - } - - } -} diff --git a/src/Spring/Spring.Core.Configuration/Properties/AssemblyInfo.cs b/src/Spring/Spring.Core.Configuration/Properties/AssemblyInfo.cs deleted file mode 100644 index 1aee5470..00000000 --- a/src/Spring/Spring.Core.Configuration/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Spring.Core.Configuration")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("Spring.Core.Configuration")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("aa7c95ac-e82f-4c33-a857-76b179c34166")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Spring/Spring.Core.Configuration/Spring.Core.Configuration.2010.csproj b/src/Spring/Spring.Core.Configuration/Spring.Core.Configuration.2010.csproj deleted file mode 100644 index 78005eb8..00000000 --- a/src/Spring/Spring.Core.Configuration/Spring.Core.Configuration.2010.csproj +++ /dev/null @@ -1,88 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {7B65D538-E863-4F57-8DDC-2C38E4150045} - Library - Properties - Spring - Spring.Core.Configuration - v3.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\..\lib\Net\2.0\Common.Logging.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - {3A3A4E65-45A6-4B20-B460-0BEDC302C02C} - Spring.Aop.2010 - - - {710961A3-0DF4-49E4-A26E-F5B9C044AC84} - Spring.Core.2010 - - - - - \ No newline at end of file diff --git a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/AssemblyTypeScannerTests.cs b/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/AssemblyTypeScannerTests.cs deleted file mode 100644 index 0a72db8f..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/AssemblyTypeScannerTests.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using Spring.Util; - -namespace Spring.Context.Attributes -{ - [TestFixture] - public class AssemblyTypeScannerTests - { - - private class Scanner : AssemblyTypeScanner - { - public Scanner(string folderScanPath) - : base(folderScanPath) - { } - - public Scanner() - : base(null) - { } - } - - private Scanner _scanner; - - private List> _excludePredicates - { - get - { - //get at the collection of excludePredicates from the private field - //(yuck!-- test smell, but at least its wrapped up in a neat private property getter!) - return (List>)(ReflectionUtils.GetInstanceFieldValue(_scanner, "_excludePredicates")); - } - } - - private List> _includePredicates - { - get - { - //get at the collection of includePredicates from the private field - //(yuck!-- test smell, but at least its wrapped up in a neat private property getter!) - return (List>)(ReflectionUtils.GetInstanceFieldValue(_scanner, "_includePredicates")); - } - } - - private List> _typeSources - { - get - { - //get at the collection of typeSources from the private field - //(yuck!-- test smell, but at least its wrapped up in a neat private property getter!) - return (List>)(ReflectionUtils.GetInstanceFieldValue(_scanner, "_typeSources")); - } - } - - [SetUp] - public void _TestSetup() - { - _scanner = new Scanner(); - } - - [Test] - public void AssemblyHavingType_T_Adds_Assembly() - { - _scanner.AssemblyHavingType(); - Assert.That(_typeSources.Any(t => t.Contains(typeof(Spring.Core.IOrdered)))); - } - - [Test] - public void IncludeType_T_Adds_Type() - { - _scanner.IncludeType(); - _scanner.IncludeType(); - - _includePredicates.Any(p => p(typeof(Spring.Core.IOrdered))); - _includePredicates.Any(p => p(typeof(Spring.Core.IPriorityOrdered))); - } - - [Test] - public void WithExcludeFilter_Excludes_Type() - { - _scanner.IncludeType(); - _scanner.IncludeType(); - _scanner.WithExcludeFilter(t => t.Name.StartsWith("TheImported")); - - Assert.That(_scanner.Scan(), Contains.Item((typeof(TheConfigurationClass)))); - Assert.False(_scanner.Scan().Contains(typeof(TheImportedConfigurationClass))); - } - - [Test] - public void WithIncludeFilter_Includes_Types() - { - _scanner.WithIncludeFilter(t => t.Name.Contains("ConfigurationClass")); - - Assert.That(_scanner.Scan(), Contains.Item((typeof(TheConfigurationClass)))); - Assert.That(_scanner.Scan(), Contains.Item((typeof(TheImportedConfigurationClass)))); - } - - } -} diff --git a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ConfigurationClassPostProcessorTests.cs b/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ConfigurationClassPostProcessorTests.cs deleted file mode 100644 index 5cb6190a..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ConfigurationClassPostProcessorTests.cs +++ /dev/null @@ -1,223 +0,0 @@ -using System; -using NUnit.Framework; -using Spring.Context.Support; -using Spring.Objects.Factory.Support; -using Spring.Context.Attributes; -using Spring.Objects.Factory.Config; -using Spring.Objects.Factory.Xml; - -namespace Spring.Context.Attributes -{ - [TestFixture] - public class ConfigurationClassPostProcessorTests - { - private GenericApplicationContext _ctx; - - [SetUp] - public void _SetUp() - { - _ctx = new GenericApplicationContext(); - - var configDefinitionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(TheConfigurationClass)); - _ctx.RegisterObjectDefinition(configDefinitionBuilder.ObjectDefinition.ObjectTypeName, configDefinitionBuilder.ObjectDefinition); - - var postProcessorDefintionBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(ConfigurationClassPostProcessor)); - _ctx.RegisterObjectDefinition(postProcessorDefintionBuilder.ObjectDefinition.ObjectTypeName, postProcessorDefintionBuilder.ObjectDefinition); - - Assert.That(_ctx.ObjectDefinitionCount, Is.EqualTo(2)); - - _ctx.Refresh(); - } - - [Test] - public void Can_Assign_Init_And_Destroy_Methods() - { - IObjectDefinition def = _ctx.GetObjectDefinition(typeof(ObjectWithInitAndDestroyMethods).Name); - - Assert.That(def, Is.Not.Null); - Assert.That(def.InitMethodName, Is.EqualTo("CallToInit")); - Assert.That(def.DestroyMethodName, Is.EqualTo("CallToDestroy")); - } - - [Test] - public void Can_Import_Configurations_From_Additional_Classes() - { - Assert.That(_ctx.GetObject(typeof(AnImportedType).Name), Is.Not.Null); - } - - [Test] - public void Can_Respect_Assigned_Aliases() - { - var firstObject = _ctx["TheFirstAlias"]; - var secondObject = _ctx["TheSecondAlias"]; - Assert.That(firstObject, Is.InstanceOf()); - Assert.That(secondObject, Is.InstanceOf()); - } - - [Test] - public void Can_Respect_Assigned_Name() - { - var result = _ctx["TheName"]; - Assert.That(result, Is.InstanceOf()); - } - - [Test] - public void Can_Respect_Default_Singleton_Scope() - { - var firstObject = (SingletonParent)_ctx[typeof(SingletonParent).Name]; - var secondObject = (SingletonParent)_ctx[typeof(SingletonParent).Name]; - - Assert.That(firstObject, Is.SameAs(secondObject)); - } - - [Test] - public void Can_Respect_Explicit_PrototypeScope() - { - var firstObject = (PrototypeChild)_ctx[typeof(PrototypeChild).Name]; - var secondObject = (PrototypeChild)_ctx[typeof(PrototypeChild).Name]; - - Assert.That(firstObject, Is.Not.SameAs(secondObject)); - } - - [Test] - public void Can_Respect_Lazy_Attribute() - { - Assert.That(_ctx.GetObjectDefinition(typeof(ImplicitLazyInitObject).Name).IsLazyInit, Is.True); - Assert.That(_ctx.GetObjectDefinition(typeof(ExplicitLazyInitObject).Name).IsLazyInit, Is.True); - Assert.That(_ctx.GetObjectDefinition(typeof(ExplicitNonLazyInitObject).Name).IsLazyInit, Is.False); - } - - [Test] - public void Can_Retreive_Actual_Objects_From_Context() - { - Assert.That(_ctx[typeof(SingletonParent).Name], Is.TypeOf()); - Assert.That(_ctx[typeof(PrototypeChild).Name], Is.TypeOf()); - } - - [Test] - public void Can_Satisfy_Dependencies_Of_Objects() - { - Assert.That(((SingletonParent)_ctx[typeof(SingletonParent).Name]).Child, Is.Not.Null); - } - - - [Test] - public void Can_Respect_Imported_Resources() - { - Assert.That(_ctx["xmlRegisteredObject"], Is.Not.Null); - } - } - - public class ObjectWithInitAndDestroyMethods - { - public void CallToDestroy() { } - public void CallToInit() { } - } - - - - - [Configuration] - [ImportResource("assembly://Spring.Core.Configuration.Tests/Spring.Context.Attributes/ObjectDefinitions.xml", DefinitionReader = typeof(XmlObjectDefinitionReader))] - public class TheImportedConfigurationClass - { - [Definition] - public virtual AnImportedType AnImportedType() - { - return new AnImportedType(); - } - } - - [Configuration] - [Import(new Type[] { typeof(TheImportedConfigurationClass) })] - public class TheConfigurationClass - { - [Definition(Names = "TheName")] - public virtual SingleNamedObject NamedObject() - { - return new SingleNamedObject(); - } - - [Definition(DestroyMethod = "CallToDestroy", InitMethod = "CallToInit")] - public virtual ObjectWithInitAndDestroyMethods ObjectWithInitAndDestroyMethods() - { - return new ObjectWithInitAndDestroyMethods(); - } - - [Definition(Names = "TheFirstAlias,TheSecondAlias")] - public virtual ObjectWithAnAlias ObjectWithAnAlias() - { - return new ObjectWithAnAlias(); - } - - [Definition] - [Scope(ObjectScope.Prototype)] - public virtual PrototypeChild PrototypeChild() - { - return new PrototypeChild(); - } - - [Definition] - public virtual SingletonParent SingletonParent() - { - return new SingletonParent(PrototypeChild()); - } - - [Definition] - [Lazy] - public virtual ImplicitLazyInitObject ImplicitLazyInitObject() - { - return new ImplicitLazyInitObject(); - } - - [Definition] - [Lazy(true)] - public virtual ExplicitLazyInitObject ExplicitLazyInitObject() - { - return new ExplicitLazyInitObject(); - } - - [Definition] - [Lazy(false)] - public virtual ExplicitNonLazyInitObject ExplicitNonLazyInitObject() - { - return new ExplicitNonLazyInitObject(); - } - - } - - public class TypeRegisteredInXml { } - - public class AnImportedType { } - - public class ImplicitLazyInitObject { } - - public class ExplicitLazyInitObject { } - - public class ExplicitNonLazyInitObject { } - - public class ObjectWithAnAlias { } - - public class SingleNamedObject { } - - public class SingletonParent - { - private PrototypeChild _child; - - public SingletonParent(PrototypeChild child) - { - _child = child; - } - - public PrototypeChild Child - { - get - { - return _child; - } - } - - } - - public class PrototypeChild { } -} diff --git a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/DefinitionAttributeTests.cs b/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/DefinitionAttributeTests.cs deleted file mode 100644 index 673a3c85..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/DefinitionAttributeTests.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using NUnit.Framework; -using Spring.Context.Attributes; - -namespace Spring.Context.Attributes -{ - [TestFixture] - public class DefinitionAttributeTests - { - [Test] - public void Can_Accept_Single_Name() - { - var def = new DefinitionAttribute(); - - def.Names = "Steve"; - - Assert.That(def.NamesToArray[0], Is.EqualTo("Steve")); - } - - - [Test] - public void Can_Accept_Multiple_Names() - { - var def = new DefinitionAttribute(); - var names = "Name1,Name2,Name3"; - - def.Names = names; - Assert.That(def.NamesToArray[0], Is.EqualTo("Name1")); - Assert.That(def.NamesToArray[1], Is.EqualTo("Name2")); - Assert.That(def.NamesToArray[2], Is.EqualTo("Name3")); - - } - - - } -} diff --git a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ImportResourceAttributeTests.cs b/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ImportResourceAttributeTests.cs deleted file mode 100644 index 6f0d4018..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ImportResourceAttributeTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using NUnit.Framework; -using Spring.Objects.Factory.Xml; -using Spring.Objects.Factory.Support; - -namespace Spring.Context.Attributes -{ - [TestFixture] - public class ImportResourceAttributeTests - { - [Test] - public void Uses_XmlObjectDefinitionReader_By_Default() - { - var attrib = new ImportResourceAttribute("the resource"); - - Assert.That(attrib.DefinitionReader, Is.EqualTo(typeof(XmlObjectDefinitionReader))); - } - - [Test] - public void Can_Assign_NonDefault_DefinitionReader() - { - var attrib = new ImportResourceAttribute("the resource"); - attrib.DefinitionReader = typeof(AbstractObjectDefinitionReader); - - Assert.That(attrib.DefinitionReader, Is.EqualTo(typeof(AbstractObjectDefinitionReader))); - } - - [Test] - public void DefinitionReader_Can_Prevent_Improper_Types() - { - ImportResourceAttribute attrib = new ImportResourceAttribute("the resource"); - - try - { - attrib.DefinitionReader = typeof(Object);// <--need to use *anything* ensured *not* to implement IObjectDefinitionReader - Assert.Fail("Expected Exception of type ArgumentException not thrown!"); - } - catch (ArgumentException) - { - //swallow the expected exception - } - - - } - } -} diff --git a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ObjectDefinitions.xml b/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ObjectDefinitions.xml deleted file mode 100644 index 5c7e700e..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Context/Attributes/ObjectDefinitions.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/test/Spring/Spring.Core.Configuration.Tests/Objects/Factory/Support/AssemblyScanningExtensionMethodsTests.cs b/test/Spring/Spring.Core.Configuration.Tests/Objects/Factory/Support/AssemblyScanningExtensionMethodsTests.cs deleted file mode 100644 index c0e0a01f..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Objects/Factory/Support/AssemblyScanningExtensionMethodsTests.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using System.Reflection; -using System.Diagnostics; -using Spring.Context.Config; -using Spring.Context.Support; -using Spring.Context.Attributes; - -namespace Spring.Objects.Factory.Support -{ - [TestFixture] - public class AssemblyScanningExtensionMethodsTests - { - private GenericApplicationContext _context; - - [SetUp] - public void _TestSetup() - { - _context = new GenericApplicationContext(); - } - - [Test] - public void Can_Filter_For_Assembly_Based_On_Assembly_Metadata() - { - _context.Scan(a => a.GetName().Name.StartsWith("Spring.Core.Configuration.")); - _context.Refresh(); - - AssertExpectedObjectsAreRegisteredWith(_context); - } - - [Test] - public void Can_Filter_For_Assembly_Containing_Specific_Type_But_Having_NO_Definitions() - { - //specifically filter assemblies for one that we *know* will result in NO [Configuration] types in it - _context.Scan(assy => assy.GetTypes().Any(type => type.FullName.Contains(typeof(Spring.Core.IOrdered).Name))); - _context.Refresh(); - - Assert.That(_context.DefaultListableObjectFactory.ObjectDefinitionCount, Is.EqualTo(0)); - } - - [Test] - public void Can_Filter_For_Assembly_Containing_Specific_Type() - { - _context.Scan(assy => assy.GetTypes().Any(type => type.FullName.Contains(typeof(MarkerTypeForScannerToFind).Name))); - _context.Refresh(); - - AssertExpectedObjectsAreRegisteredWith(_context); - } - - [Test] - public void Can_Filter_For_Specific_Type() - { - _context.Scan(type => ((Type)type).FullName.Contains(typeof(TheImportedConfigurationClass).Name)); - _context.Refresh(); - - Assert.That(_context.DefaultListableObjectFactory.ObjectDefinitionCount, Is.EqualTo(4)); - } - - [Test] - public void Can_Filter_For_Specific_Types_With_Compound_Predicate() - { - _context.Scan(type => ((Type)type).FullName.Contains(typeof(TheImportedConfigurationClass).Name) || ((Type)type).FullName.Contains(typeof(TheConfigurationClass).Name)); - _context.Refresh(); - - AssertExpectedObjectsAreRegisteredWith(_context); - } - - [Test] - public void Can_Filter_For_Specific_Types_With_Multiple_Include_Filters() - { - var scanner = new AssemblyObjectDefinitionScanner(); - scanner.WithIncludeFilter(type => ((Type)type).FullName.Contains(typeof(TheImportedConfigurationClass).Name)); - scanner.WithIncludeFilter(type => ((Type)type).FullName.Contains(typeof(TheConfigurationClass).Name)); - - _context.Scan(scanner); - _context.Refresh(); - - AssertExpectedObjectsAreRegisteredWith(_context); - } - - [Test] - public void Can_Perform_Scan_With_No_Filtering() - { - _context.Scan(); - _context.Refresh(); - - AssertExpectedObjectsAreRegisteredWith(_context); - } - - private void AssertExpectedObjectsAreRegisteredWith(GenericApplicationContext _context) - { - Assert.That(_context.DefaultListableObjectFactory.ObjectDefinitionCount, Is.EqualTo(13)); - } - - } - - public class MarkerTypeForScannerToFind - { - - } -} diff --git a/test/Spring/Spring.Core.Configuration.Tests/Properties/AssemblyInfo.cs b/test/Spring/Spring.Core.Configuration.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index a1c1539d..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Spring.Core.Configuration.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("Spring.Core.Configuration.Tests")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("65e12092-0586-435f-b9ef-e4a35c302bef")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/test/Spring/Spring.Core.Configuration.Tests/Spring.Core.Configuration.Tests.2010.csproj b/test/Spring/Spring.Core.Configuration.Tests/Spring.Core.Configuration.Tests.2010.csproj deleted file mode 100644 index 859e1c50..00000000 --- a/test/Spring/Spring.Core.Configuration.Tests/Spring.Core.Configuration.Tests.2010.csproj +++ /dev/null @@ -1,85 +0,0 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {4F1A206C-09A8-43FF-B791-FE956E99A120} - Library - Properties - Spring - Spring.Core.Configuration.Tests - v4.0 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\..\lib\Net\2.0\nunit.framework.dll - - - - - - - - - - - - - - - - - {3A3A4E65-45A6-4B20-B460-0BEDC302C02C} - Spring.Aop.2010 - - - {7B65D538-E863-4F57-8DDC-2C38E4150045} - Spring.Core.Configuration.2010 - - - {710961A3-0DF4-49E4-A26E-F5B9C044AC84} - Spring.Core.2010 - - - {44B16BAA-6DF8-447C-9D7F-3AD3D854D904} - Spring.Core.Tests.2010 - - - - - - - - Designer - - - - - \ No newline at end of file