ComplexMovieListerFactory Class – Spring Java

package moviefindertest.springxml;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;

public class ComplexMovieListerFactory implements BeanFactoryAware {
      
      private ListableBeanFactory beanFactory;

      @Override
      public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
            this.beanFactory = (ListableBeanFactory)beanFactory;
      }
      
      public MovieLister build()
      {
            Map<String, Movie> allMovies = beanFactory.getBeansOfType(Movie.class);
            List<Movie> movies = new ArrayList<Movie>();
            for(Movie movie : allMovies.values())
            {
                  movies.add(movie);
            }

            ComplexMovieFinder complexMovieFinder = new ComplexMovieFinder();
            complexMovieFinder.setMovies(movies);
            MovieLister complexMovieLister = new MovieLister(complexMovieFinder);
            return complexMovieLister;
      }

}
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s