Source Code Cross Referenced for Country.java in  » Testing » databene-benerator » org » databene » region » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » databene benerator » org.databene.region 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (c) Copyright 2007 by Volker Bergmann. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, is permitted under the terms of the
006:         * GNU General Public License.
007:         *
008:         * For redistributing this software or a derivative work under a license other
009:         * than the GPL-compatible Free Software License as defined by the Free
010:         * Software Foundation or approved by OSI, you must first obtain a commercial
011:         * license to this software product from Volker Bergmann.
012:         *
013:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014:         * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015:         * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017:         * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024:         * POSSIBILITY OF SUCH DAMAGE.
025:         */
026:
027:        package org.databene.region;
028:
029:        import org.databene.commons.ConfigurationError;
030:        import org.databene.commons.ArrayUtil;
031:        import org.databene.commons.OrderedMap;
032:        import org.databene.document.csv.CSVLineIterator;
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:
036:        import java.util.*;
037:        import java.io.IOException;
038:
039:        /**
040:         * Represents a country, provides constants for most bigger countries and serves as a generator for city object.
041:         * Country information is read from the file org/databene/domain/address/country.csv.<br/>
042:         * <br/>
043:         * Created: 11.06.2006 08:15:37
044:         */
045:        public class Country {
046:
047:            private static final Log logger = LogFactory.getLog(Country.class);
048:
049:            private static String FILE_NAME = "org/databene/domain/address/country.csv";
050:
051:            private static Map<String, Country> instances = new HashMap<String, Country>(
052:                    250);
053:
054:            static {
055:                parseConfigFile();
056:            }
057:
058:            public static final Country GERMANY = getInstance("DE");
059:            public static final Country AUSTRIA = getInstance("AT");
060:            public static final Country SWITZERLAND = getInstance("CH");
061:            public static final Country LIECHTENSTEIN = getInstance("LI");
062:
063:            public static final Country BELGIUM = getInstance("BE");
064:            public static final Country NETHERLANDS = getInstance("NL");
065:            public static final Country LUXEMBURG = getInstance("LU");
066:
067:            public static final Country ITALY = getInstance("IT");
068:            public static final Country FRANCE = getInstance("FR");
069:            public static final Country SPAIN = getInstance("ES");
070:            public static final Country PORTUGAL = getInstance("PT");
071:            public static final Country ANDORRA = getInstance("AD");
072:
073:            public static final Country GREECE = getInstance("gr");
074:
075:            public static final Country SLOWENIA = getInstance("SI");
076:            public static final Country CZECH_REPUBLIC = getInstance("CZ");
077:            public static final Country HUNGARY = getInstance("HR");
078:            public static final Country POLAND = getInstance("PL");
079:            public static final Country RUSSIA = getInstance("RU");
080:            public static final Country ROMANIA = getInstance("RO");
081:            public static final Country BULGARIA = getInstance("BG");
082:            public static final Country CROATIA = getInstance("HR");
083:            public static final Country BOSNIA_AND_HERZEGOVINA = getInstance("BA");
084:            public static final Country TURKEY = getInstance("TR");
085:            public static final Country ESTONIA = getInstance("EE");
086:            public static final Country LITHUANIA = getInstance("LT");
087:            public static final Country LATVIA = getInstance("LV");
088:
089:            public static final Country UNITED_KINGDOM = getInstance("UK");
090:            public static final Country DENMARK = getInstance("DK");
091:            public static final Country SWEDEN = getInstance("SE");
092:            public static final Country NORWAY = getInstance("NO");
093:            public static final Country FINLAND = getInstance("FI");
094:            public static final Country IRELAND = getInstance("IE");
095:            public static final Country ICELAND = getInstance("IS");
096:
097:            public static final Country USA = getInstance("US");
098:            public static final Country JAPAN = getInstance("JP");
099:
100:            private static Country defaultCountry;
101:
102:            static {
103:                defaultCountry = Country.getInstance(Locale.getDefault()
104:                        .getCountry().toLowerCase());
105:            }
106:
107:            private static void parseConfigFile() {
108:                CSVLineIterator iterator = null;
109:                try {
110:                    iterator = new CSVLineIterator(FILE_NAME, ',', true);
111:                    logger.debug("Parsing country setup file " + FILE_NAME);
112:                    while (iterator.hasNext()) {
113:                        String[] cells = iterator.next();
114:                        String isoCode = cells[0];
115:                        String phoneCode = (cells.length > 1 ? cells[1] : null);
116:                        String[] mobilCodes = (cells.length > 2 ? ArrayUtil
117:                                .copyOfRange(cells, 2, cells.length - 2)
118:                                : new String[] { "???" });
119:                        Country country = new Country(isoCode, phoneCode,
120:                                mobilCodes);
121:                        if (logger.isDebugEnabled())
122:                            logger.debug("parsed " + country);
123:                    }
124:                } catch (IOException e) {
125:                    throw new ConfigurationError(
126:                            "Country definition file could not be processed. ",
127:                            e);
128:                } finally {
129:                    if (iterator != null)
130:                        iterator.close();
131:                }
132:            }
133:
134:            private String isoCode;
135:            private Region region;
136:            private String phoneCode;
137:            private String[] mobileCodes;
138:            private Locale countryLocale;
139:            private Map<String, State> states;
140:
141:            private Country(String isoCode, String phoneCode,
142:                    String... mobileCodes) {
143:                this .isoCode = isoCode;
144:                this .phoneCode = phoneCode;
145:                this .countryLocale = new Locale("xx", isoCode);
146:                this .region = new BasicRegion(isoCode);
147:                this .mobileCodes = mobileCodes;
148:                this .states = new OrderedMap<String, State>();
149:                instances.put(isoCode, this );
150:            }
151:
152:            public String getIsoCode() {
153:                return isoCode;
154:            }
155:
156:            public String getName() {
157:                return countryLocale.getDisplayCountry(Locale.getDefault());
158:            }
159:
160:            /*
161:             public void setDisplayLocale(Locale displayLocale) {
162:             this.displayLocale = displayLocale;
163:             }
164:             */
165:            public String getPhoneCode() {
166:                return phoneCode;
167:            }
168:
169:            public String[] getMobileCodes() {
170:                return mobileCodes;
171:            }
172:
173:            public Region getRegion() {
174:                return region;
175:            }
176:
177:            public State getState(String stateId) {
178:                return states.get(stateId);
179:            }
180:
181:            public Collection<State> getStates() {
182:                return states.values();
183:            }
184:
185:            public void addState(String id, State state) {
186:                state.setCountry(this );
187:                states.put(id, state);
188:            }
189:
190:            public String toString() {
191:                return getName();
192:            }
193:
194:            public static Collection<Country> getInstances() {
195:                return instances.values();
196:            }
197:
198:            /**
199:             * Retrieves a country from the country configuration file.
200:             * @param isoCode the ISO code of the country to retrieve
201:             * @return if it is a predfined country, an instance with the configured data is returned,
202:             * else one with the specified ISO code and default settings, e.g. phoneCode 'UNKNOWN'.
203:             */
204:            public static Country getInstance(String isoCode) {
205:                Country country = instances.get(isoCode.toUpperCase());
206:                if (country == null)
207:                    country = new Country(isoCode, "UNKNOWN");
208:                return country;
209:            }
210:
211:            public static Country getDefault() {
212:                return defaultCountry;
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.