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<br />

Working with Collections and<br />

Custom Types<br />

You need to start adding some useful data and some special types to your <strong>Spring</strong> application. In this chapter, you will<br />

learn how to interact with data using collections within the <strong>Spring</strong> <strong>Framework</strong>.<br />

So far, you have declared several beans that hold your type of documents, but there should be a better way to do<br />

that. I know that you are thinking of some kind of database or some other local storage or even a flat file, but let’s see<br />

how <strong>Spring</strong> can help you to define your types in a different way, by using them as a collection.<br />

List, Map, and Properties<br />

First, let’s modify the Java classes so you can get an idea of what you will actually need in your final context<br />

configuration as shown in Listing 5-1.<br />

Listing 5-1. DocumentRepository.java<br />

package com.apress.isf.spring.data;<br />

import java.util.List;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import com.apress.isf.java.model.Document;<br />

public class DocumentRepository implements DocumentDAO {<br />

private static final Logger log = LoggerFactory.getLogger(DocumentRepository.class);<br />

private List documents = null;<br />

public List getDocuments() {<br />

return documents;<br />

}<br />

public void setDocuments(List documents) {<br />

this.documents = documents;<br />

}<br />

53

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

Saved successfully!

Ooh no, something went wrong!