com.mycompany.service.impl
Class CountryServiceImpl

java.lang.Object
  extended by com.mycompany.service.impl.AbstractService
      extended by com.mycompany.service.impl.CountryServiceImpl
All Implemented Interfaces:
CountryService

@Named(value="countryService")
public class CountryServiceImpl
extends AbstractService
implements CountryService

Controller class for countries. Since this class holds application-wide state, namely a list of Country objects, we annotate it as an application-scoped CDI bean.

Author:
Ian Hlavats (ian@tarantulaconsulting.com)

Constructor Summary
CountryServiceImpl()
           
 
Method Summary
 ProvinceState createProvinceState(Country country, java.lang.String name)
          Creates a ProvinceState object for a particular Country.
 java.util.List<City> findCitiesByState(ProvinceState state)
          Finds a list of City objects for the given ProvinceState.
 City findCity(java.lang.String name, ProvinceState provinceState)
          Finds a City by name in the ProvinceState.
 City findCityById(java.lang.Integer id)
          Finds a City object by ID.
 Country findCountryById(java.lang.Integer id)
          Finds a Country object by ID.
 java.util.List<ProvinceState> findProvinceStatesByCountry(Country country)
          Finds a List of ProvinceState objects for a particular Country.
 ProvinceState findStateById(java.lang.Integer id)
          Finds a ProvinceState object by ID.
 ProvinceState findStateByName(Country country, java.lang.String stateName)
          Finds a ProvinceState object by name within a particular Country.
 java.util.List<Country> getCountries()
          Returns all Country objects.
 java.util.List<ProvinceState> getProvinceStates()
          Returns all ProvinceState objects.
 void init(javax.servlet.ServletContext context)
          This method is responsible for initializing a List of Country objects when the web application is started.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CountryServiceImpl

public CountryServiceImpl()
Method Detail

createProvinceState

public ProvinceState createProvinceState(Country country,
                                         java.lang.String name)
Description copied from interface: CountryService
Creates a ProvinceState object for a particular Country.

Specified by:
createProvinceState in interface CountryService
Parameters:
country - The Country in which the ProvinceState is located.
name - The name of the ProvinceState.
Returns:
The newly created ProvinceState object.

findCitiesByState

public java.util.List<City> findCitiesByState(ProvinceState state)
Description copied from interface: CountryService
Finds a list of City objects for the given ProvinceState.

Specified by:
findCitiesByState in interface CountryService
Parameters:
state - The ProvinceState object for which to find cities.
Returns:
A List of City objects.

findCity

public City findCity(java.lang.String name,
                     ProvinceState provinceState)
Description copied from interface: CountryService
Finds a City by name in the ProvinceState.

Specified by:
findCity in interface CountryService
Parameters:
name - The name of the city.
provinceState - The province/state in which to find the city.
Returns:
A City object.

findCityById

public City findCityById(java.lang.Integer id)
Description copied from interface: CountryService
Finds a City object by ID.

Specified by:
findCityById in interface CountryService
Parameters:
id - The ID of the city.
Returns:
A City object.

findCountryById

public Country findCountryById(java.lang.Integer id)
Description copied from interface: CountryService
Finds a Country object by ID.

Specified by:
findCountryById in interface CountryService
Parameters:
id - The ID of the country.
Returns:
A Country object.

findProvinceStatesByCountry

public java.util.List<ProvinceState> findProvinceStatesByCountry(Country country)
Description copied from interface: CountryService
Finds a List of ProvinceState objects for a particular Country.

Specified by:
findProvinceStatesByCountry in interface CountryService
Parameters:
country - The Country object.
Returns:
A List of ProvinceState objects.

findStateById

public ProvinceState findStateById(java.lang.Integer id)
Description copied from interface: CountryService
Finds a ProvinceState object by ID.

Specified by:
findStateById in interface CountryService
Parameters:
id - The ID of the ProvinceState object.
Returns:
A ProvinceState object.

findStateByName

public ProvinceState findStateByName(Country country,
                                     java.lang.String stateName)
Description copied from interface: CountryService
Finds a ProvinceState object by name within a particular Country.

Specified by:
findStateByName in interface CountryService
Parameters:
country - The Country object.
stateName - The name of the ProvinceState to find.
Returns:
A ProvinceState object.

getCountries

public java.util.List<Country> getCountries()
Description copied from interface: CountryService
Returns all Country objects.

Specified by:
getCountries in interface CountryService
Returns:
A List of Country objects.

getProvinceStates

public java.util.List<ProvinceState> getProvinceStates()
Description copied from interface: CountryService
Returns all ProvinceState objects.

Specified by:
getProvinceStates in interface CountryService
Returns:
A List of ProvinceState objects.

init

public void init(@Observes
                 javax.servlet.ServletContext context)
          throws java.lang.Exception
This method is responsible for initializing a List of Country objects when the web application is started. We use the CDI event handling system combined with the custom Initialized event to ensure this method is called at startup time. Note: since this class is not an EJB, to insert data we have to use bean-managed transactions with the UserTransaction.

Specified by:
init in interface CountryService
Parameters:
context -
Throws:
java.lang.Exception
See Also:
ServletContextLifecycleNotifier