Java Reference
In-Depth Information
<bean id="sequenceGenerator"
class="com.apress.springenterpriserecipes.sequence.SequenceGenerator"
p:prefix="30" p:suffix="A" p:initial="100000" />
</beans>
Configuring Collections for Your Beans
List , Set , and Map are the core interfaces representing three main types of collections. For each
collection type, Java provides several implementations with different functions and characteristics from
which you can choose. In Spring, these types of collections can be easily configured with a group of
built-in XML tags, such as <list> , <set> , and <map> .
Suppose you are going to allow more than one suffix for your sequence generator. The suffixes will
be appended to the sequence numbers with hyphens as the separators. You may consider accepting
suffixes of arbitrary data types and converting them into strings when appending to the sequence
numbers.
Lists, Arrays, and Sets
First, let's use a java.util.List collection to contain your suffixes. A list is an ordered and indexed
collection whose elements can be accessed either by index or with a for-each loop.
package com.apress.springenterpriserecipes.sequence;
...
public class SequenceGenerator {
...
private List<Object> suffixes;
public void setSuffixes( List<Object> suffixes) {
this.suffixes = suffixes;
}
public void setPrefixGenerator(PrefixGenerator prefixGenerator) {
this.prefixGenerator = prefixGenerator;
}
public synchronized String getSequence() {
StringBuffer buffer = new StringBuffer();
...
for (Object suffix : suffixes) {
buffer.append("-");
buffer.append(suffix);
}
return buffer.toString();
}
}
Search WWH ::




Custom Search