Changed lines at line 1
1: ----
2: 1 Injecting enums in Spring
3: To inject java.commons.lang.Enum, we need to use the static method and pass in the String. ie given:
4: {code:java}
5: import org.apache.commons.lang.enum.Enum;
6: public final class SortEnum extends Enum {
7: /** ascending sort order. */
8: public static final SortEnum ASC = new SortEnum("ASC");
9: /** descending sort. */
10: public static final SortEnum DESC = new SortEnum("DESC");
11: /** no sort order specified. */
12: public static final SortEnum NO_SORT = new SortEnum("NO_SORT");
13: /**
14: * callers should use convience methods.
15: * @param dir to sort
16: */
17: private SortEnum(String dir) {
18: super(dir);
19: }
20: /**
21: * SortEnum to use.
22: * @param dir requied
23: * @return enum represention for the dir
24: */
25: public static SortEnum getEnum(String dir) {
26: return (SortEnum) getEnum(SortEnum.class, dir);
27: }
28: }
29: {code}
30: {code:xml}
31: <beans>
32: <bean id="ASC"
33: class="com.marandcustomsolutions.SortOrder"
34: factory-method="getEnum" singleton="true">
35: <constructor-arg><value>ASC</value> </constructor-arg>
36: </bean>
37: </beans>
38: {code}
39: ----
40: 1 Injecting list, set, map, and props
41: {code:xml}
42: <bean id="moreComplexObject" class="example.ComplexObject">
43: <!-- results in a setPeople(java.util.Properties) call -->
44: <property name="people">
45: <props>
46: <prop key="HarryPotter">The magic property</prop>
47: <prop key="JerrySeinfeld">The funny property</prop>
48: </props>
49: </property>
50: <!-- results in a setSomeList(java.util.List) call -->
51: <property name="someList">
52: <list>
53: <value>a list element followed by a reference</value>
54: <ref bean="myDataSource"/>
55: </list>
56: </property>
57: <!-- results in a setSomeMap(java.util.Map) call -->
58: <property name="someMap">
59: <map>
60: <entry>
61: <key><value>yup an entry</value></key>
62: <value>just some string</value>
63: </entry>
64: <entry>
65: <key><value>yup a ref</value></key>
66: <ref bean="myDataSource"/>
67: </entry>
68: </map>
69: </property>
70: <!-- results in a setSomeSet(java.util.Set) call -->
71: <property name="someSet">
72: <set>
73: <value>just some string</value>
74: <ref bean="myDataSource"/>
75: </set>
76: </property>
77: {code}
78: 1 Related Topics:
79: ----
80: ~~
81: [Development/Java & J2EE/Spring/Enums] |
82: [Development/Java & J2EE/Spring/Validation]~~\\
83: ----
84: \\