work on SPRNET-987 and SPRNET-1214

This commit is contained in:
markpollack
2010-07-22 15:52:26 +00:00
parent 3dc044203c
commit 90a8415720
7 changed files with 69 additions and 10 deletions

View File

@@ -188,12 +188,24 @@ namespace Spring.Objects.Factory.Config
}
}
foreach (DictionaryEntry entry in other.NamedArgumentValues)
{
NamedArgumentValues.Add(entry.Key, entry.Value);
{
AddOrMergeNamedArgumentValues(entry.Key, entry.Value);
//NamedArgumentValues.Add(entry.Key, entry.Value);
}
}
}
private void AddOrMergeNamedArgumentValues(object key, object newValue)
{
if (_namedArgumentValues.Contains(key) )
{
_namedArgumentValues[key] = newValue;
} else
{
_namedArgumentValues.Add(key, newValue);
}
}
private void AddOrMergeIndexedArgumentValues(int key, ValueHolder newValue)
{
ValueHolder currentValue = _indexedArgumentValues[key] as ValueHolder;

View File

@@ -324,19 +324,39 @@ namespace Spring.Objects.Factory.Config
}
Hashtable mods = new Hashtable();
bool entriesModified = false;
foreach (DictionaryEntry entry in dictVal)
{
/*
object oldValue = entry.Value;
object newValue = ResolveValue(oldValue);
if (!ObjectUtils.NullSafeEquals(newValue, oldValue))
{
mods[entry.Key] = newValue;
}*/
object key = entry.Key;
object newKey = ResolveValue(key);
object oldValue = entry.Value;
object newValue = ResolveValue(oldValue);
if (!ObjectUtils.NullSafeEquals(newValue, oldValue) || key != newKey)
{
entriesModified = true;
}
mods[newKey] = newValue;
}
if (entriesModified)
{
dictVal.Clear();
foreach (DictionaryEntry entry in mods)
{
dictVal[entry.Key] = entry.Value;
}
}
foreach (DictionaryEntry entry in mods)
{
dictVal[entry.Key] = entry.Value;
}
}
/// <summary>

View File

@@ -25,7 +25,7 @@ limitations under the License.
</property>
<property name="PeriodicTable">
<dictionary key-type="${dictionaryKeyType}" value-type="${dictionaryValueType}">
<entry key="C" value="carbon"/>
<entry key="${entryKey}" value="carbon"/>
<entry key="O" value="oxygen"/>
</dictionary>
</property>
@@ -45,6 +45,7 @@ limitations under the License.
<add key="dictionaryKeyType" value="string" />
<add key="dictionaryValueType" value="string" />
<add key="setElementType" value="string" />
<add key="entryKey" value="C"/>
</name-values>
</property>
</object>

View File

@@ -11,6 +11,11 @@
</property>
<!-- age should inherit value of 1 from parent -->
</object>
<object id="inheritsFromParentFactoryUsingCtor"
parent="inheritedTestObjectUsingCtor">
<constructor-arg name="name" value="child-name"/>
<!-- age should inherit value of 1 from parent -->
</object>
<object id="protoypeInheritsFromParentFactorySingleton"
parent="inheritedTestObject"

View File

@@ -5,6 +5,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="inheritedTestObjectUsingCtor" type="Spring.Objects.TestObject, Spring.Core.Tests" abstract="true">
<constructor-arg name="name" value="parent"/>
<constructor-arg name="age" value="1"/>
</object>
<object id="inheritedTestObject" type="Spring.Objects.TestObject, Spring.Core.Tests" abstract="true">
<property name="name"><value>parent</value></property>
<property name="age"><value>1</value></property>

View File

@@ -597,6 +597,7 @@ namespace Spring.Objects.Factory.Config
Assert.AreEqual(2, to.Pets.Count);
Assert.AreEqual(2, to.PeriodicTable.Count);
Assert.AreEqual(2, to.Computers.Count);
Assert.IsTrue(to.PeriodicTable.Contains("C"));
}
}
}

View File

@@ -667,7 +667,21 @@ namespace Spring.Objects.Factory.Xml
// Age property is inherited from object in parent factory
Assert.IsTrue(inherits.Age == 1);
TestObject inherits2 = (TestObject) child.GetObject("inheritsFromParentFactory");
Assert.IsTrue(inherits2 == inherits);
Assert.AreSame(inherits2,inherits);
}
[Test]
public void SingletonInheritanceFromParentFactorySingletonUsingCtor()
{
XmlObjectFactory parent = new XmlObjectFactory(new ReadOnlyXmlTestResource("parent.xml", GetType()));
XmlObjectFactory child = new XmlObjectFactory(new ReadOnlyXmlTestResource("child.xml", GetType()), parent);
TestObject inherits = (TestObject)child.GetObject("inheritsFromParentFactoryUsingCtor");
// Name property value is overriden
Assert.IsTrue(inherits.Name.Equals("child-name"));
// Age property is inherited from object in parent factory
Assert.IsTrue(inherits.Age == 1);
TestObject inherits2 = (TestObject)child.GetObject("inheritsFromParentFactoryUsingCtor");
Assert.AreSame(inherits2,inherits);
}
[Test]
@@ -681,7 +695,7 @@ namespace Spring.Objects.Factory.Xml
// Age property is inherited from object in parent factory
Assert.IsTrue(inherits.Age == 2);
TestObject inherits2 = (TestObject) child.GetObject("prototypeInheritsFromParentFactoryPrototype");
Assert.IsFalse(inherits2 == inherits);
Assert.AreNotSame(inherits2,inherits);
inherits2.Age = 13;
Assert.IsTrue(inherits2.Age == 13);
// Shouldn't have changed first instance
@@ -699,7 +713,7 @@ namespace Spring.Objects.Factory.Xml
// Age property is inherited from object in parent factory
Assert.IsTrue(inherits.Age == 1);
TestObject inherits2 = (TestObject) child.GetObject("protoypeInheritsFromParentFactorySingleton");
Assert.IsFalse(inherits2 == inherits);
Assert.AreNotSame(inherits2,inherits);
inherits2.Age = 13;
Assert.IsTrue(inherits2.Age == 13);
// Shouldn't have changed first instance