Set each field with a
@Resource annotation in the target object, to the value of a resource whose name is the simple name of the target class followed by "." followed by the name of the field. If the key
@Resource parameter is specified, then a resource with that name is used instead. Array valued fields can also be initialized with resources whose names end with "[index]". For example:
class MyClass { @Resource String sOne; @Resource(key="sTwo") String s2; @Resource int[] numbers = new int[2]; }
Given the previous class and the following resource file:
MyClass.sOne = One sTwo = Two MyClass.numbers[0] = 10 MyClass.numbers[1] = 11
Then
injectFields(new MyClass()) would initialize the MyClass
sOne field to "One", the
s2 field to "Two", and the two elements of the numbers array to 10 and 11.
If target is null an IllegalArgumentException is thrown. If an error occurs during resource lookup, then an unchecked LookupException is thrown. If a target field marked with @Resource can't be set, then an unchecked InjectFieldException is thrown.
@param target the object whose fields will be initialized
@throws LookupException if an error occurs during lookup or string conversion
@throws InjectFieldException if a field can't be set
@throws IllegalArgumentException if target is null
@see #getObject