fixed SPRNET-1231
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#endregion
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Context.Support
|
||||
{
|
||||
/// <summary>
|
||||
@@ -80,7 +82,7 @@ namespace Spring.Context.Support
|
||||
/// <seealso cref="Spring.Core.IO.ConfigurableResourceLoader"/>
|
||||
public class XmlApplicationContext : AbstractXmlApplicationContext
|
||||
{
|
||||
private string[] _configurationLocations;
|
||||
private readonly string[] _configurationLocations;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
@@ -214,6 +216,7 @@ namespace Spring.Context.Support
|
||||
_configurationLocations = configurationLocations;
|
||||
if (refresh)
|
||||
{
|
||||
AssertUtils.ArgumentHasElements(configurationLocations, "configurationLocations");
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +178,6 @@ namespace Spring.Objects.Factory.Support
|
||||
/// </returns>
|
||||
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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
|
||||
<object id='testOFPP' type='Spring.Context.Support.XmlApplicationContextTests+SPRNET1231ObjectFactoryPostProcessor' />
|
||||
|
||||
<object id='testFactory' type='Spring.Context.Support.XmlApplicationContextTests+SPRNET1231FactoryObject' />
|
||||
|
||||
<object id='testFactoryProduct' factory-object='testFactory' factory-method='GetProduct' />
|
||||
|
||||
</objects>
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -770,6 +770,7 @@
|
||||
<EmbeddedResource Include="Core\IO\TestResource.txt" />
|
||||
<EmbeddedResource Include="Context\Support\innerObjectsWithPostProcessor.xml" />
|
||||
<EmbeddedResource Include="Core\IO\ConfigSectionResourceTests_config1.xml" />
|
||||
<EmbeddedResource Include="Context\Support\XmlApplicationContextTests-SPRNET1231.xml" />
|
||||
<Content Include="Data\PathMatcher\EmptyPattern.test" />
|
||||
<Content Include="Data\PathMatcher\Examples.test" />
|
||||
<Content Include="Data\PathMatcher\InBetween.test" />
|
||||
|
||||
Reference in New Issue
Block a user