View Full Version : MethodInvokingFactoryObject, documentation and properties
Tom Whitner
11-22-2004, 07:38 PM
I have been experimenting with the MethodInvokingFactoryObject class and have the following two observations.
#1. The documentation for this class both in the SDK chm and the PDF is a little light. This is a rather abstract concept and some more concrete and complete examples would be useful here.
#2. The class seems to allow for the invocation of static or instance methods, but what about properties? I would recommend adding a TargetProperty property to allow for property invocation.
Thanks,
Tom
Mark Pollack
11-22-2004, 08:48 PM
Hi Tom,
You may also be interested in using the factory-method attribute as an alternative to MethodInvokingFactoryObject. See Section 3.2.3.2 and 3.2.3.3 in the user docs. (http://www.springframework.net/doc/reference/objects.html#objects-factory-class)
Did you take a look at PropertyRetrievingFactoryObject (http://www.springframework.net/doc/reference/objects.html#d0e2049) in Section 3.16.2? That may meet your needs for setting based on a property value.
I've added your documentation request as a Jira Item (http://opensource.atlassian.com/projects/spring/browse/SPRNET-11) and will include it in the 0.6.0 final release.
Thanks,
Mark
Tom Whitner
11-23-2004, 01:23 AM
Hey, that's no fair. That section doesn't exist in the PDF that I have from 0.6 RC1 !! The PropertyRetrievingFactoryObject is exactly what I was suggesting to add. Also note that the example for the PropertyRetrievingFactoryObject is exactly in line with what I would like to see for the MethodInvokingFactoryObject
Mark Pollack
11-23-2004, 02:35 AM
Hi,
Hmmm...that is strange..I'll look into that discrepancy... Sorry for the confusion...
Cheers,
Mark
Tesuji
08-16-2005, 03:40 PM
I'm new to Spring and immediately ran into a limitation of MethodInvokingFactoryObject as well.
I need to call a static method that takes a string as an argument to do some initialization. The same string is also used elsewhere. It seems however the Arguments list only accepts <value> elements and no <ref> elements.
Any Ideas how I can fix this? Below I've put the XML I use, there's a comment at the spot where I'd like to use a reference instead of a value:
<objects>
<object name="TestServerName" type="string">
<constructor-arg index="0" value="TestServer"/>
</object>
<object name="TestTraderName" type="string">
<constructor-arg index="0" value="TestTrader"/>
</object>
<object id="TestClientRequestTopic" type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject, Spring.Core">
<property name="TargetType">
<value>StockFutureTrader.Common.SubscriptionTopics</value>
</property>
<property name="TargetMethod">
<value>GetRequestTopic</value>
</property>
<property name="Arguments">
<list>
<value>TestServer</value>
</list>
</property>
</object>
<object name="TestClientMessageBus"
type="AtomPro.Messaging.Spread.MessageBus, AtomPro.Messaging.Spread">
</object>
<object name="TestExchangeMessageBus"
type="AtomPro.Messaging.IntraProcessMessageBus, AtomPro.Messaging">
</object>
<object name="TestClientRequestHandler"
type="AtomPro.Framework.RequestResponse.RequestHandler, AtomPro.Framework">
<constructor-arg index="0" ref="TestClientMessageBus"/>;
<constructor-arg index="1" ref="TestClientRequestTopic"/>;
</object>
<object name="TestExchangeSimulatorServer"
type="StockFutureTrader.Server.Tests.ExchangeSimulatorSe rver, StockFutureTrader">
<constructor-arg index="0" ref="TestServerName"/>;
</object>
<object name="TestOrderManagerClient"
type="StockFutureTrader.Client.OrderManagerClient, StockFutureTrader">
<constructor-arg index="0" ref="TestClientRequestHandler"/>;
<constructor-arg index="1" ref="TestClientMessageBus"/>;
<constructor-arg index="2" ref="TestTraderName"/>;
</object>
</objects>
Rick Evans
08-16-2005, 06:13 PM
Hiya
Try the following...
<ref local="TestServerName"/>
In the case of your example, one would use it like so...
<objects>
<object id="TestClientRequestTopic" type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject, Spring.Core">
<property name="TargetType">
<value>StockFutureTrader.Common.SubscriptionTopics</value>
</property>
<property name="TargetMethod">
<value>GetRequestTopic</value>
</property>
<property name="Arguments">
<list>
<ref local="TestServerName"/>
</list>
</property>
</object>
</objects>
You can stick anything you want (references to other objects, inner object definitions, values, lists, dictionaries, name value collections, and sets) inside the initial argument list.
I will amend the API documentation for the MethodInvokingFactoryObject (http://www.springframework.net/doc/api/html/Spring.Objects.Factory.Config.MethodInvokingFactor yObject.html) class to include an example that uses something other than <value/> elements for the 'arguments' property.
Apologies for any confusion that this may have caused, ciao
Rick
Tesuji
08-17-2005, 09:13 AM
Hiya
Try the following...
<ref local="TestServerName"/>
...
I will amend the API documentation for the MethodInvokingFactoryObject (http://www.springframework.net/doc/api/html/Spring.Objects.Factory.Config.MethodInvokingFactor yObject.html) class to include an example that uses something other than <value/> elements for the 'arguments' property.
Apologies for any confusion that this may have caused, ciao
Rick
Thanks, that does what I wanted indeed.
I had focused on arguments in the examples and documentation, so that's why I didn't find it. I think adding an example for passing a 'ref' to a method is a good idea. It will help newbies like me, the amount of information is overwhelming at first.
Knowing where to look now, reading the documentation section "Referring to collaborating objects" however says 'local' can only refer to an 'id' where I only supplied a name. It works though... Maybe 'id' and 'name' are equal when either is not specified?
Anyway, thanks for the quick reply. And thanks for supplying such a wonderful framework, it's what I have been wishing for for years.
Rick Evans
08-18-2005, 08:25 AM
Hiya
Just a short note to say that this issue has been resolved. Anything else? :D
http://opensource.atlassian.com/projects/spring/browse/SPRNET-161
Ciao
Rick
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.