Issue Details (XML | Word | Printable)

Key: SPR-1620
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: alberto manjarrez
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

A factory that takes an argument

Created: 17/Jan/06 11:46 AM   Updated: 31/May/06 05:36 AM
Component/s: SpringCORE
Affects Version/s: 2.0 M2
Fix Version/s: None

Time Tracking:
Not Specified

Virtual Machine: Sun JVM - 1.4
Platform: IBM WebSphere - 5.1


 Description  « Hide
A common pattern on a factory is to have a "discriminator" (argument) in the creation method. For example:

createInstance(int type);
createInstance(String type);
createInstance(Locale locale);

This is used to determine which specific instance needs to be created. Hence the API of the FactoryBean shoul be extended to support something like:

getObject(Object arg) or getObject(Object[] args)

This of course will have to be propagated to other interfaces and classes. For example:
the AbstractFactoryBean createInstance should be extended to support createInstance (Object arg);
or the BeanFactory getBean should be extended to support getBean(String id, Object arg);



 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
alberto manjarrez added a comment - 19/Jan/06 08:18 AM
I forgot to mention that the "discriminator" is only known at Runtime. The runtime data is not a single time dynamic value that can be set with a "post-processor" as it can possibly change in each getBean request.
 
The factory may create share instances or prototype.

Shared instance example:
- Consider a service to handle a request base on the Local (i.e. a different shared instance of the service should be located based on the Local)
- Another example is a handler service to handle a JMS message base on the message type or header

Prototype example:
- The creation of a translated data bean from the JMS Message type (i.e. JMS Message to domain object mapping. A new instance per received message)