I want to have a List or Array of some sort, storing this information about each country:
- 2 letter code
- Country name such as Brazil
- Continent/region of the world such as Eastern Europe, North America, etc.
I will classify each country into the region/continent manually (but if there exists a way to do this automatically, do let me know). This question is about how to store and access the countries. For example, I want to be able to retrieve all the countries in North America.
I don’t want to use local text files or such because this project will be converted to javascript using Google Web Toolkit. But storing in an Enum or another resource file of some sort, keeping it separate from the rest of the code, is what I’m really after.
There is 246 countries in ISO 3166, you might get a relay big enum on back of this. I prefer to use XML file with list of countries, you can download one from http://www.iso.org/ and load them (e.g. when app is starting).
Than, as you need them in GWT load them in back as RPC call, but remember to cache those (some kind of lazy loading) so you wont finish with loading them each time.
I think this would be anyway better than holding them in code, as you will finish with loading full list each time module is accessed, even if user will not need to use this list.
So you need something which will hold country:
For GWT this class would need to implement IsSerializable.
And you can load those, on server side using:
Of course, if you need to find country by ISO 2 letter code you might wont to change List to Map probably.
If, as you mentioned, you need separate countries by continent, you might extend XML from ISO 3166 and add your own elements. Just check their (ISO website) license.