Java Reference
In-Depth Information
Adding a stateless bean
So, the first bean we will create is
com.packtpub.wflydevelopment.chapter3.boundary.TheatreInfo ,
which barely contains the logic to look up the list of theatre seats. In practice, this bean acts
as a facade for our singleton bean, as shown in the following code:
@Stateless
@Remote(TheatreInfoRemote.class)
public class TheatreInfo implements TheatreInfoRemote {
@EJB
private TheatreBox box;
@Override
public String printSeatList() {
final Collection<Seat> seats = box.getSeats();
final StringBuilder sb = new StringBuilder();
for (Seat seat : seats) {
sb.append(seat.toString());
sb.append(System.lineSeparator());
}
return sb.toString();
}
}
Since we are planning to invoke this EJB from a remote client, we defined a remote inter-
face for it with the @Remote(TheatreInfoRemote.class) annotation.
Next, take a look at the @EJB TheatreBox box , which can be used to safely inject an
EJB into your class without the need of a manual JNDI lookup. This practice can be used to
increase the portability of your application between different application servers, where dif-
ferent JNDI rules might exist.
The remote interface of your bean will be as simple as the following code:
public interface TheatreInfoRemote {
String printSeatList();
}
Search WWH ::




Custom Search