From 522d55ca2a83831ee18694a24d6d13d01111e5ef Mon Sep 17 00:00:00 2001 From: eeichinger Date: Wed, 22 Jul 2009 18:09:24 +0000 Subject: [PATCH] fixed SPRNET-1231 --- .../Support/AbstractXmlApplicationContext.cs | 2 +- .../Context/Support/XmlApplicationContext.cs | 5 +- .../AbstractAutowireCapableObjectFactory.cs | 5 -- .../Support/DefaultListableObjectFactory.cs | 89 ------------------- .../Context/Support/ContextRegistryTests.cs | 11 ++- .../XmlApplicationContextTests-SPRNET1231.xml | 10 +++ .../Support/XmlApplicationContextTests.cs | 29 ++++++ .../Spring.Core.Tests.2008.csproj | 1 + 8 files changed, 52 insertions(+), 100 deletions(-) create mode 100644 test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests-SPRNET1231.xml diff --git a/src/Spring/Spring.Core/Context/Support/AbstractXmlApplicationContext.cs b/src/Spring/Spring.Core/Context/Support/AbstractXmlApplicationContext.cs index c76603a6..0d23203c 100644 --- a/src/Spring/Spring.Core/Context/Support/AbstractXmlApplicationContext.cs +++ b/src/Spring/Spring.Core/Context/Support/AbstractXmlApplicationContext.cs @@ -116,7 +116,7 @@ namespace Spring.Context.Support protected override void RefreshObjectFactory() { // Shut down previous object factory, if any. - IConfigurableListableObjectFactory oldObjectFactory = _objectFactory; + DefaultListableObjectFactory oldObjectFactory = _objectFactory; _objectFactory = null; if (oldObjectFactory != null) diff --git a/src/Spring/Spring.Core/Context/Support/XmlApplicationContext.cs b/src/Spring/Spring.Core/Context/Support/XmlApplicationContext.cs index 91669a26..80cd607e 100644 --- a/src/Spring/Spring.Core/Context/Support/XmlApplicationContext.cs +++ b/src/Spring/Spring.Core/Context/Support/XmlApplicationContext.cs @@ -18,6 +18,8 @@ #endregion +using Spring.Util; + namespace Spring.Context.Support { /// @@ -80,7 +82,7 @@ namespace Spring.Context.Support /// public class XmlApplicationContext : AbstractXmlApplicationContext { - private string[] _configurationLocations; + private readonly string[] _configurationLocations; /// /// Creates a new instance of the @@ -214,6 +216,7 @@ namespace Spring.Context.Support _configurationLocations = configurationLocations; if (refresh) { + AssertUtils.ArgumentHasElements(configurationLocations, "configurationLocations"); Refresh(); } } diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs index 92875548..a68000e3 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs @@ -178,11 +178,6 @@ namespace Spring.Objects.Factory.Support /// protected override Type GetTypeForFactoryMethod(string objectName, RootObjectDefinition definition) { - if (StringUtils.HasText(definition.FactoryObjectName) && definition.IsSingleton && !definition.IsLazyInit) - { - return GetObject(objectName).GetType(); - } - Type factoryType = null; bool isStatic = true; diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs index 50ffab07..f2c38ff9 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/DefaultListableObjectFactory.cs @@ -907,95 +907,6 @@ namespace Spring.Objects.Factory.Support return (objectType != null && typeof(IFactoryObject).IsAssignableFrom(objectType)); } - private IList DoGetObjectNamesForTypeOld(Type type, bool includePrototypes, bool includeFactoryObjects) - { - bool isFactoryType = (type != null && typeof(IFactoryObject).IsAssignableFrom(type)); - IList result = new ArrayList(); - // if (type != null) - { - string[] objectNames = GetObjectDefinitionNames(); - foreach (string objectName in objectNames) - { - // only check object definition if it is not an alias for another object - if (IsAlias(objectName)) continue; - - RootObjectDefinition rod = GetMergedObjectDefinition(objectName, false); // TODO: check merge ancestors w/ Java - // only check complete object definitions... - if (!rod.IsAbstract && rod.HasObjectType) - { - // return the return type of an object created via a factory method... - if (StringUtils.HasText(rod.FactoryMethodName)) - { - Type methodType = GetTypeForFactoryMethod(objectName, rod); - if (methodType != null - && type.IsAssignableFrom(methodType)) - { - result.Add(objectName); - } - } - // in the case of an IFactoryObject, match the object created by the IFactoryObject... - else if (typeof(IFactoryObject).IsAssignableFrom(rod.ObjectType) && !isFactoryType) - { - if (includeFactoryObjects && (includePrototypes || IsSingleton(objectName)) && - IsObjectTypeMatch(objectName, type)) - { - result.Add(objectName); - } - } - else - { - string factoryObjectName = objectName; - // if type to match is an IFactoryObject, match the IFactoryObject itself; - // else, match the object instance... - if (isFactoryType) - { - factoryObjectName = ObjectFactoryUtils.BuildFactoryObjectName(objectName); - } - if ((includePrototypes || rod.IsSingleton) && //MLP - (type.IsAssignableFrom(rod.ObjectType))) - { - result.Add(factoryObjectName); - } - } - } - } - - // check singletons too, to catch manually registered singletons... - string[] singletonNames = GetSingletonNames(); - foreach (string objectName in singletonNames) - { - // only check if manually registered... - if (!ContainsObjectDefinition(objectName)) - { - // in the case of an IFactoryObject, match the object created by the IFactoryObject... - if (IsFactoryObject(objectName) && !isFactoryType) - { - if (includeFactoryObjects && (includePrototypes || IsSingleton(objectName)) && - IsObjectTypeMatch(objectName, type)) - { - result.Add(objectName); - } - } - else - { - string factoryObjectName = objectName; - // if type to match is an IFactoryObject, match the IFactoryObject itself... - // else, match the object instance... - if (isFactoryType) - { - factoryObjectName = ObjectFactoryUtils.BuildFactoryObjectName(objectName); - } - if (IsObjectTypeMatch(factoryObjectName, type)) - { - result.Add(factoryObjectName); - } - } - } - } - } - return result; - } - #endregion /// diff --git a/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs b/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs index d5111d25..cdf29c65 100644 --- a/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs +++ b/test/Spring/Spring.Core.Tests/Context/Support/ContextRegistryTests.cs @@ -185,20 +185,23 @@ namespace Spring.Context.Support typeBuilder.TargetType = typeof(TestObject); Type proxyType = typeBuilder.BuildProxyType(); - XmlApplicationContext ctx1 = new XmlApplicationContext(); + DefaultListableObjectFactory of = new DefaultListableObjectFactory(); RootObjectDefinition od1 = new RootObjectDefinition(proxyType, false); od1.PropertyValues.Add("Name", "Bruno"); - ((DefaultListableObjectFactory)ctx1.ObjectFactory).RegisterObjectDefinition("testObject", od1); + of.RegisterObjectDefinition("testObject", od1); + + GenericApplicationContext ctx1 = new GenericApplicationContext(of); ContextRegistry.RegisterContext(ctx1); ITestObject to1 = ContextRegistry.GetContext().GetObject("testObject") as ITestObject; Assert.IsNotNull(to1); Assert.AreEqual("Bruno", to1.Name); - XmlApplicationContext ctx2 = new XmlApplicationContext(); + DefaultListableObjectFactory of2 = new DefaultListableObjectFactory(); RootObjectDefinition od2 = new RootObjectDefinition(proxyType, false); od2.PropertyValues.Add("Name", "Baia"); - ((DefaultListableObjectFactory)ctx2.ObjectFactory).RegisterObjectDefinition("testObject", od2); + of2.RegisterObjectDefinition("testObject", od2); + GenericApplicationContext ctx2 = new GenericApplicationContext(of2); ContextRegistry.Clear(); diff --git a/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests-SPRNET1231.xml b/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests-SPRNET1231.xml new file mode 100644 index 00000000..b440a927 --- /dev/null +++ b/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests-SPRNET1231.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests.cs b/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests.cs index 6c18c54b..a8856188 100644 --- a/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests.cs +++ b/test/Spring/Spring.Core.Tests/Context/Support/XmlApplicationContextTests.cs @@ -35,6 +35,35 @@ namespace Spring.Context.Support [TestFixture] public sealed class XmlApplicationContextTests { + [Test(Description = "http://jira.springframework.org/browse/SPRNET-1231")] + public void SPRNET1231_DoesNotInvokeFactoryMethodDuringObjectFactoryPostProcessing() + { + string configLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "XmlApplicationContextTests-SPRNET1231.xml"); + XmlApplicationContext ctx = new XmlApplicationContext(configLocation); + + } + + private class SPRNET1231ObjectFactoryPostProcessor : IObjectFactoryPostProcessor + { + public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) + { + SPRNET1231FactoryObject testFactory = (SPRNET1231FactoryObject)factory.GetObject("testFactory"); + Assert.AreEqual(0, testFactory.count); + } + } + + private class SPRNET1231FactoryObject + { + public int count; + + public ITestObject GetProduct() + { + count++; + return new TestObject("test" + count, count); + } + } + + [Test] public void InnerObjectWithPostProcessing() { diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj index 0cd3561c..0d8f3925 100644 --- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj +++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj @@ -770,6 +770,7 @@ +