GeoSoft API

no.geosoft.cc.country
Class CountryManager

Object
  |
  +--CountryManager

public class CountryManager
extends Object

A country management singelton module. Useful for presentation of sorted list of countries in GUI like in country combo boxes etc.

The country manager instantiate country objects for the countries listed in the countries.txt resource of this package. The file lists ISO codes and the official english names for countries of the world. The countries.txt file has the following layout:

    AF; AFGHANISTAN
    AL; ALBANIA
    DZ; ALGERIA
    AS; AMERICAN SAMOA
    AD; ANDORRA
    AO; ANGOLA
    :
 
The country name is the defualt name used if a localized mapping is not found, or the client askes for countries independent of locale.

TODO: Connect to an online resource to pick country ISO codes.

For internal application usage, only ISO codes for countries should be used (i.e. for persistent storage store the ISO code rather than a country name).

In user interfaces, localized names should be used according to the locale of the application or preferred locale selected by the user. Localized names are maintained in resource bundles picked from property files with name Messages_xx_XX.properties where xx is the language specifier and XX is the country specifier. Provide localized country name mappings for all locales supported by the client application. The properties files should be located in the same package as the CountryManager. The properties files has the following format (Messages_en_US.properties):

    AF = Afghanistan
    AL = Albania
    DZ = Algeria
    AS = American Samoa
    AD = Andorra
    AO = Angola
    :
 

Typical usage:

    // Get a specific country
    Country country = CountryManager.getInstance().getCountry ("AF", french);

    // Get world countries localized to french (assuming
    // Messages_fr_FR.properties is available).
    Locale french = new Locale ("fr", "FR");
    Collection countries = CountryManager.getInstance.getCountries (french);

    // Put countries (sorted according to locale) in a combo box
    TreeSet sorted = new TreeSet (countries);
    JComboBox countriesCombo = new JComboBox (new Vector (sorted));
 

Author:
GeoSoft
See Also:
ISO standard

Method Summary
 Collection getCountries()
          Return countries of the world (as specified in countries.txt) using the default (official ISO name) country names.
 Collection getCountries(Locale locale)
          Return countries of the world (as specified in countries.txt) with names according to the specified locale.
 Country getCountry(String isoCode)
          Get country for specified ISO code.
 Country getCountry(String isoCode, Locale locale)
          Get country for specified ISO code.
static CountryManager getInstance()
          Retur sole instance of this class.
static void main(String[] args)
          Testing the class.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static CountryManager getInstance()
Retur sole instance of this class.

Returns:
CountryManager singleton instance.

getCountries

public Collection getCountries()
Return countries of the world (as specified in countries.txt) using the default (official ISO name) country names.

Returns:
Countries of the world.

getCountries

public Collection getCountries(Locale locale)
Return countries of the world (as specified in countries.txt) with names according to the specified locale. The name mappings must be available in a Messages_xx_XX.properties file where xx and XX match the language and country of the specified locale respectively.

If the associated properties file is not found, the country names are set according to the default ISO standard.

Parameters:
locale - Locale to setting country names.
Returns:
Countries of the world.

getCountry

public Country getCountry(String isoCode)
Get country for specified ISO code.

Parameters:
isoCode - ISO code of country to find.
Returns:
Requested country (with default ISO name) (or null if ISO code is unknown).

getCountry

public Country getCountry(String isoCode,
                          Locale locale)
Get country for specified ISO code.

Parameters:
isoCode - ISO code of country to find.
locale - Locale to control name of requested country.
Returns:
Requested country (or null if ISO code is unknown).

main

public static void main(String[] args)
Testing the class.

Parameters:
args - Not used.

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no