PDA

View Full Version : Factory Import External Xml Problem


Adam Levitt
06-23-2005, 08:07 PM
I am currently using the XmlObjectFactory from Spring.NET release 0.6. I am making the following call in my code:

IResource resource = new FileSystemResource("spring.xml");
XmlObjectFactory xmlObjectFactory = new XmlObjectFactory(resource);
IDestinationManager dManager = (DefaultDestinationManager) xmlObjectFactory.GetObject("destinationManager");

My spring.xml file looks like this:

<objects xmlns="http://www.springframework.net">
<import resource="queues.xml" />
<object id="destinationManager" type="Arch.Messaging.DefaultDestinationManager, Arch.Messaging">
<property name="queues">
<dictionary>
<entry key="queue1">
<ref object="myQueue1" />
</entry>
</dictionary>
</property>
...
</object>
...
</objects>

The problem here is that when I include the definition for "queue1" in the same xml file (spring.xml), everything works properly. However, if I take the object definitions for the queues and put them into "queues.xml" which resides in the same directory as "spring.xml", and include the <import resource="queues.xml" /> tag, I get the following exception:

XmlException parsing XML document from file [c:\projects-net\ArchMessaging\conf\spring.xml]
at Spring.Objects.Factory.Xml.XmlObjectDefinitionRead er.LoadObjec
tDefinitions(IResource resource)
at Spring.Objects.Factory.Xml.XmlObjectFactory..ctor( IResource re
source)
at Arch.Messaging.DestinationManagerTest.Setup() in C:\projects-n
et\ArchMessaging\src\Arch.Messaging\TestSuite\Arch .Messaging\DestinationManagerTest.cs:line 37

My "queues.xml" file looks like this:

<objects xmlns="http://www.springframework.net">
<object id="myQueue1" type="Arch.Messaging.Queue, Arch.Messaging">
<constructor-arg type="string" index="0">
<value>queue/DummyQueue</value>
</constructor-arg>
...
</object>
...
</object>

Any pointers in the right direction would be much appreciated. I'm struggling to figure out if this is a bug or if I am doing something incorrectly.

Thanks,
Adam

Rick Evans
06-23-2005, 10:18 PM
Hiya

Short answer... put the <import resource="..."/> after all of your <object/> elements.

To wit...

<objects xmlns="http://www.springframework.net">

<object id="destinationManager" type="Arch.Messaging.DefaultDestinationManager, Arch.Messaging">
<property name="queues">
<dictionary>
<entry key="queue1">
<ref object="myQueue1" />
</entry>
</dictionary>
</property>
...
</object>
...
<import resource="queues.xml" />
</objects>

I will post again on this subject, but I first have to go have a cup of tea... because I can't quite believe it myself :shock:

Ciao
Rick

Rick Evans
06-23-2005, 10:56 PM
Hiya

Thanks for spotting this Adam... I have amended the XSD document such that <import/> tags now have to come before <object/> tags... it just feels more natural that way doesn't it? The attendant unit tests have been changed accordingly, and I have updated the reference documentation too.

Time for another cup of Tetleys. Cheers again Adam :)

Ciao
Rick

Adam Levitt
06-23-2005, 11:02 PM
Rick -- thanks for the quick response. Yes, in the documentation it says to put the imports at the top. This is also the convention for Spring for Java.

Thanks once again!