Source Code Cross Referenced for ICUServiceTestSample.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » util » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *******************************************************************************
003:         * Copyright (C) 2001-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */package com.ibm.icu.dev.test.util;
007:
008:        import com.ibm.icu.impl.ICULocaleService;
009:        import com.ibm.icu.impl.ICUService;
010:        import com.ibm.icu.text.Collator;
011:        import com.ibm.icu.util.ULocale;
012:
013:        import java.util.EventListener;
014:        import java.util.Iterator;
015:        import java.util.Map;
016:        import java.util.Map.Entry;
017:        import java.util.Set;
018:        import java.util.SortedMap;
019:
020:        public class ICUServiceTestSample {
021:            static public void main(String[] args) {
022:                HelloServiceClient client = new HelloServiceClient();
023:
024:                Thread t = new HelloUpdateThread();
025:                t.start();
026:                try {
027:                    t.join();
028:                } catch (InterruptedException e) {
029:                }
030:                System.out.println("done");
031:                if (client == null) {
032:                }
033:            }
034:
035:            /**
036:             * A class that displays the current names in the Hello service.
037:             * Each time the service changes, it redisplays the names.
038:             */
039:            static class HelloServiceClient implements 
040:                    HelloService.HelloServiceListener {
041:
042:                HelloServiceClient() {
043:                    HelloService.addListener(this );
044:                    display();
045:                }
046:
047:                /**
048:                 * This will be called in the notification thread of
049:                 * ICUNotifier.  ICUNotifier could spawn a (non-daemon) thread
050:                 * for each listener, so that impolite listeners wouldn't hold
051:                 * up notification, but right now it doesn't.  Instead, all
052:                 * notifications are delivered on the notification thread.
053:                 * Since that's a daemon thread, a notification might not
054:                 * complete before main terminates.  
055:                 */
056:                public void helloServiceChanged() {
057:                    display();
058:                }
059:
060:                private void display() {
061:                    Map names = HelloService.getDisplayNames(ULocale.US);
062:                    System.out
063:                            .println("displaying " + names.size() + " names.");
064:                    Iterator iter = names.entrySet().iterator();
065:                    while (iter.hasNext()) {
066:                        Entry entry = (Entry) iter.next();
067:                        String displayName = (String) entry.getKey();
068:                        HelloService service = HelloService.get((String) entry
069:                                .getValue());
070:                        System.out.println(displayName + " says "
071:                                + service.hello());
072:                        try {
073:                            Thread.sleep(50);
074:                        } catch (InterruptedException e) {
075:                        }
076:                    }
077:                    System.out.println("----");
078:                }
079:            }
080:
081:            /**
082:             * A thread to update the service.
083:             */
084:            static class HelloUpdateThread extends Thread {
085:                String[][] updates = { { "Hey", "en_US_INFORMAL" },
086:                        { "Hallo", "de_DE_INFORMAL" },
087:                        { "Yo!", "en_US_CALIFORNIA_INFORMAL" },
088:                        { "Chi Fanle Ma?", "zh__INFORMAL" },
089:                        { "Munch munch... Burger?", "en" }, { "Sniff", "fr" },
090:                        { "TongZhi! MaoZeDong SiXiang Wan Sui!", "zh_CN" },
091:                        { "Bier? Ja!", "de" }, };
092:
093:                public void run() {
094:                    for (int i = 0; i < updates.length; ++i) {
095:                        try {
096:                            Thread.sleep(500);
097:                        } catch (InterruptedException e) {
098:                        }
099:                        HelloService.register(updates[i][0], new ULocale(
100:                                updates[i][1]));
101:                    }
102:                }
103:            }
104:
105:            /**
106:             * An example service that wraps an ICU service in order to export custom API and
107:             * notification. The service just implements 'hello'.
108:             */
109:            static final class HelloService {
110:                private static ICUService registry;
111:                private String name;
112:
113:                private HelloService(String name) {
114:                    this .name = name;
115:                }
116:
117:                /**
118:                 * The hello service...
119:                 */
120:                public String hello() {
121:                    return name;
122:                }
123:
124:                public String toString() {
125:                    return super .toString() + ": " + name;
126:                }
127:
128:                /**
129:                 * Deferred init.
130:                 */
131:                private static ICUService registry() {
132:                    if (registry == null) {
133:                        initRegistry();
134:                    }
135:                    return registry;
136:                }
137:
138:                private static void initRegistry() {
139:                    registry = new ICULocaleService() {
140:                        protected boolean acceptsListener(EventListener l) {
141:                            return true; // we already verify in our wrapper APIs
142:                        }
143:
144:                        protected void notifyListener(EventListener l) {
145:                            ((HelloServiceListener) l).helloServiceChanged();
146:                        }
147:                    };
148:
149:                    // initialize
150:                    doRegister("Hello", "en");
151:                    doRegister("Bonjour", "fr");
152:                    doRegister("Ni Hao", "zh_CN");
153:                    doRegister("Guten Tag", "de");
154:                }
155:
156:                /**
157:                 * A custom listener for changes to this service.  We don't need to
158:                 * point to the service since it is defined by this class and not
159:                 * an object.
160:                 */
161:                public static interface HelloServiceListener extends
162:                        EventListener {
163:                    public void helloServiceChanged();
164:                }
165:
166:                /**
167:                 * Type-safe notification for this service.
168:                 */
169:                public static void addListener(HelloServiceListener l) {
170:                    registry().addListener(l);
171:                }
172:
173:                /**
174:                 * Type-safe notification for this service.
175:                 */
176:                public static void removeListener(HelloServiceListener l) {
177:                    registry().removeListener(l);
178:                }
179:
180:                /**
181:                 * Type-safe access to the service.
182:                 */
183:                public static HelloService get(String id) {
184:                    return (HelloService) registry().get(id);
185:                }
186:
187:                public static Set getVisibleIDs() {
188:                    return registry().getVisibleIDs();
189:                }
190:
191:                public static Map getDisplayNames(ULocale locale) {
192:                    return getDisplayNames(registry(), locale);
193:                }
194:
195:                /**
196:                 * Register a new hello string for this locale.
197:                 */
198:                public static void register(String helloString, ULocale locale) {
199:                    if (helloString == null || locale == null) {
200:                        throw new NullPointerException();
201:                    }
202:                    doRegister(helloString, locale.toString());
203:                }
204:
205:                private static void doRegister(String hello, String id) {
206:                    registry().registerObject(new HelloService(hello), id);
207:                }
208:
209:                /**
210:                 * Convenience override of getDisplayNames(ULocale, Comparator, String) that
211:                 * uses the default collator for the locale as the comparator to
212:                 * sort the display names, and null for the matchID.
213:                 */
214:                public static SortedMap getDisplayNames(ICUService service,
215:                        ULocale locale) {
216:                    Collator col = Collator.getInstance(locale);
217:                    return service.getDisplayNames(locale, col, null);
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.