Actually, for my needs, I think this could be accomplished without explicit JDK 1.5 support if Spring provided a simple way to lookup any constant style value (public static final T X = Y). How about this algorithm:
Code:
For a particular property (P), if there is no default conversion or property editor for P's type (T) then attempt to take the String value in the XML and lookup a public static final field of type T against T's class as the new property value (V). If found, then set P to V.
Say I have this setter:
Code:
public void setType(AccountType type) { ... }
and this XML:
Code:
<property name="type"><value>ASSET</value></property>
There is no defaul or automatic conversion available (type isn't a primitive or anything), so Spring would look for a property editor. In our example, there would be no property editor, so Spring would now look for a public static final field named ASSET in the AccountType class (that would itself be an instance of AccountType). If found, Spring would pass in this public static final AccountType instance to setType(...). Maybe another step in the algorithm would be to look for a public static valueOf method that takes a String argument and returns the class type?
Also, I believe it would be useful to do field lookups for constants in general. Say I have an old-style int constant:
Code:
public void setType(int accountType) { ... }
Maybe I could do something like:
Code:
<property name="type"><value-of>com.mypackage.Constants.ASSET_TYPE</value-of></property>
Thoughts?
- Andy