25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14<br />

Using Dynamic Languages<br />

Often you are required to do some business logic as fast as possible, such as a prototype that needs to work or a quick<br />

security authorization check or calculating some hash. In this chapter, you are going to see how the use of dynamic<br />

languages together with the <strong>Spring</strong> <strong>Framework</strong> can help you to do such tasks.<br />

Get More Dynamic<br />

The <strong>Spring</strong> <strong>Framework</strong> supports Groovy, JRuby, and BeanShell dynamic languages and you can interact with them<br />

like any other bean defined in the container. Remember the Login interface and Login implementation? Let’s review<br />

them. See Listings 14-1 and 14-2.<br />

Listing 14-1. Login.java<br />

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

public interface Login {<br />

public boolean isAuthorized(String email, String pass);<br />

}<br />

Listing 14-1 shows the Login interface with only one method, isAuthorized, which takes two parameters, the<br />

e-mail and the password. Listing 14-2 shows its implementation.<br />

Listing 14-2. LoginService.java<br />

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

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

public class LoginService implements Login {<br />

private String username;<br />

private String password;<br />

public String getUsername() {<br />

return username;<br />

}<br />

public void setUsername(String username) {<br />

this.username = username;<br />

}<br />

195

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

Saved successfully!

Ooh no, something went wrong!