01: package example;
02:
03: import java.util.ArrayList;
04:
05: import javax.webbeans.Component;
06: import javax.webbeans.In;
07:
08: @Component
09: public class MovieLister {
10: @In
11: private MovieFinder _finder;
12:
13: /**
14: * Returns movies by a particular director.
15: */
16: public Movie[] moviesDirectedBy(String director) {
17: ArrayList<Movie> movieList = new ArrayList<Movie>();
18:
19: for (Movie movie : _finder.findAll()) {
20: if (director.equals(movie.getDirector()))
21: movieList.add(movie);
22: }
23:
24: return (Movie[]) movieList.toArray(new Movie[movieList.size()]);
25: }
26: }
|