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 3 ■ Applying Different Configurations<br />

In Listing 3-9, you are going to create the AnnotatedDocumentRepository class. This class will have another<br />

marker or stereotype, @Repository, and this class will be injected into your SearchEngine implementation with the<br />

@Autowired annotation (see Listing 3-8).<br />

Listing 3-9. AnnotatedDocumentRespository.java<br />

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

import java.util.ArrayList;<br />

import java.util.List;<br />

import org.springframework.stereotype.Repository;<br />

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

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

import com.apress.isf.spring.data.DocumentDAO;<br />

@Repository("documentDAO")<br />

public class AnnotatedDocumentRepository implements DocumentDAO {<br />

public Document[] getAll() {<br />

return storage();<br />

}<br />

private Document[] storage(){<br />

List result = new ArrayList();<br />

Type type = new Type();<br />

type.setName("PDF");<br />

type.setDesc("Portable Document Format");<br />

type.setExtension(".pdf");<br />

Document document = new Document();<br />

document.setName("Book Template");<br />

document.setType(type);<br />

document.setLocation("/Users/felipeg/Documents/Random/Book Template.pdf");<br />

result.add(document);<br />

document = new Document();<br />

document.setName("Sample Contract");<br />

document.setType(type);<br />

document.setLocation("/Users/felipeg/Documents/Contracts/Sample Contract.pdf");<br />

result.add(document);<br />

type = new Type();<br />

type.setName("NOTE");<br />

type.setDesc("Text Notes");<br />

type.setExtension(".txt");<br />

35

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

Saved successfully!

Ooh no, something went wrong!