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 8 ■ Give Advice to Your <strong>Spring</strong> Application<br />

Let’s start modifying your code and getting rid of the logs from your classes. Remember that you need to take care<br />

of the logging concern by separating it from the classes to avoid scattering and tangling. You are going to start with the<br />

SearchEngine.java class, adding a new method just for testing one of your advice types (see Listing 8-2), then your<br />

SearchEngineService.java class (see Listing 8-3).<br />

Listing 8-2. SearchEngine.java<br />

package com.apress.isf.java.service;<br />

import java.util.List;<br />

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

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

public interface SearchEngine {<br />

public List findByType(Type documentType);<br />

public List listAll();<br />

}<br />

public List findByLocation(String location);<br />

Listing 8-3. SearchEngineService.java<br />

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

import java.util.ArrayList;<br />

import java.util.Arrays;<br />

import java.util.List;<br />

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

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

import com.apress.isf.java.service.SearchEngine;<br />

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

public class SearchEngineService implements SearchEngine {<br />

private DocumentDAO documentDAO;<br />

public SearchEngineService(){<br />

}<br />

public DocumentDAO getDocumentDAO() {<br />

return documentDAO;<br />

}<br />

public void setDocumentDAO(DocumentDAO documentDAO) {<br />

this.documentDAO = documentDAO;<br />

}<br />

93

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

Saved successfully!

Ooh no, something went wrong!