25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ Working with Collections and Custom Types<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

In the mydocuments-context.xml file (see Listing 5-4) you modified the documentDAO bean to reflect the new<br />

list and also you modified the typeDAO bean so now it can accept a Map with some entries, but wait! I think I need to<br />

explain how the <strong>Spring</strong> <strong>Framework</strong> works with collections, right?<br />

The <strong>Spring</strong> <strong>Framework</strong> allows you to use Java Collections right out the box, with the (java.util.List<br />

type), (java.util.Map type), (java.util.Properties type) and (java.util.Set type) tags<br />

shown in Table 5-1.<br />

Table 5-1. Collections Tags<br />

Element<br />

<br />

<br />

<br />

Description<br />

This tag allows duplicates. The tags , , and are the possible<br />

children of the tag.<br />

This tag doesn’t accept duplicates. The tags , , and are the<br />

possible children of the tag.<br />

This tag is a name-value pair. Both values are Strings. and are the children tags. This is a reference to the java.util.Properties class.<br />

This tag is a name-value pair; both values can be any type. ,<br />

, , and are the possible children of the<br />

tag. This is a reference of the java.util.Map class.<br />

So if you want to apply the to your documentDAO bean and to your typeDAO bean, first you need<br />

to modify your DocumentRepository and the TypeDataRepository classes to reflect the new type java.util.Set and<br />

java.util.Properties, respectively. Let’s review Listing 5-5, your XML configuration.<br />

56

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!