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


001:        /*
002:         ******************************************************************************
003:         * Copyright (C) 2004-2006, International Business Machines Corporation and        *
004:         * others. All Rights Reserved.                                               *
005:         ******************************************************************************
006:         */
007:
008:        package com.ibm.icu.impl;
009:
010:        import java.io.InputStream;
011:        import java.util.Enumeration;
012:        import java.util.MissingResourceException;
013:        import java.util.PropertyResourceBundle;
014:        import java.util.ResourceBundle;
015:        import java.util.Vector;
016:
017:        import com.ibm.icu.util.ULocale;
018:        import com.ibm.icu.util.UResourceBundle;
019:
020:        /**
021:         * just a wrapper for Java ListResourceBundles and 
022:         * @author ram
023:         *
024:         */
025:        public class ResourceBundleWrapper extends UResourceBundle {
026:            private ResourceBundle bundle = null;
027:            private String localeID = null;
028:            private String baseName = null;
029:            private Vector keys = null;
030:            private int loadingStatus = -1;
031:
032:            private ResourceBundleWrapper(ResourceBundle bundle) {
033:                this .bundle = bundle;
034:            }
035:
036:            protected void setLoadingStatus(int newStatus) {
037:                loadingStatus = newStatus;
038:            }
039:
040:            protected Object handleGetObject(String key) {
041:                ResourceBundleWrapper current = this ;
042:                Object obj = null;
043:                while (current != null) {
044:                    try {
045:                        obj = current.bundle.getObject(key);
046:                        break;
047:                    } catch (MissingResourceException ex) {
048:                        current = (ResourceBundleWrapper) current.getParent();
049:                    }
050:                }
051:                if (obj == null) {
052:                    throw new MissingResourceException(
053:                            "Can't find resource for bundle " + baseName
054:                                    + ", key " + key,
055:                            this .getClass().getName(), key);
056:                }
057:                return obj;
058:            }
059:
060:            public Enumeration getKeys() {
061:                return keys.elements();
062:            }
063:
064:            private void initKeysVector() {
065:                ResourceBundleWrapper current = this ;
066:                keys = new Vector();
067:                while (current != null) {
068:                    Enumeration e = current.bundle.getKeys();
069:                    while (e.hasMoreElements()) {
070:                        String elem = (String) e.nextElement();
071:                        if (!keys.contains(elem)) {
072:                            keys.add(elem);
073:                        }
074:                    }
075:                    current = (ResourceBundleWrapper) current.getParent();
076:                }
077:            }
078:
079:            protected String getLocaleID() {
080:                return localeID;
081:            }
082:
083:            protected String getBaseName() {
084:                return bundle.getClass().getName().replace('.', '/');
085:            }
086:
087:            public ULocale getULocale() {
088:                return new ULocale(localeID);
089:            }
090:
091:            public UResourceBundle getParent() {
092:                return (UResourceBundle) parent;
093:            }
094:
095:            // Flag for enabling/disabling debugging code
096:            private static final boolean DEBUG = ICUDebug
097:                    .enabled("resourceBundleWrapper");
098:
099:            // This method is for super class's instantiateBundle method
100:            public static UResourceBundle getBundleInstance(String baseName,
101:                    String localeID, ClassLoader root, boolean disableFallback) {
102:                UResourceBundle b = instantiateBundle(baseName, localeID, root,
103:                        disableFallback);
104:                if (b == null) {
105:                    String separator = "_";
106:                    if (baseName.indexOf('/') >= 0) {
107:                        separator = "/";
108:                    }
109:                    throw new MissingResourceException(
110:                            "Could not find the bundle " + baseName + separator
111:                                    + localeID, "", "");
112:                }
113:                return b;
114:            }
115:
116:            // recursively build bundle and override the super-class method
117:            protected static synchronized UResourceBundle instantiateBundle(
118:                    String baseName, String localeID, ClassLoader root,
119:                    boolean disableFallback) {
120:                if (root == null) {
121:                    // we're on the bootstrap
122:                    root = ClassLoader.getSystemClassLoader();
123:                }
124:                final ClassLoader cl = root;
125:                String name = baseName;
126:                ULocale defaultLocale = ULocale.getDefault();
127:                if (localeID.length() != 0) {
128:                    name = name + "_" + localeID;
129:                }
130:
131:                ResourceBundleWrapper b = (ResourceBundleWrapper) loadFromCache(
132:                        cl, name, defaultLocale);
133:                if (b == null) {
134:                    ResourceBundleWrapper parent = null;
135:                    int i = localeID.lastIndexOf('_');
136:
137:                    if (i != -1) {
138:                        String locName = localeID.substring(0, i);
139:                        parent = (ResourceBundleWrapper) loadFromCache(cl,
140:                                baseName + "_" + locName, defaultLocale);
141:                        if (parent == null) {
142:                            parent = (ResourceBundleWrapper) instantiateBundle(
143:                                    baseName, locName, cl, disableFallback);
144:                        }
145:                    } else if (localeID.length() > 0) {
146:                        parent = (ResourceBundleWrapper) loadFromCache(cl,
147:                                baseName, defaultLocale);
148:                        if (parent == null) {
149:                            parent = (ResourceBundleWrapper) instantiateBundle(
150:                                    baseName, "", cl, disableFallback);
151:                        }
152:                    }
153:                    try {
154:                        Class cls = cl.loadClass(name);
155:                        ResourceBundle bx = (ResourceBundle) cls.newInstance();
156:                        b = new ResourceBundleWrapper(bx);
157:                        if (parent != null) {
158:                            b.setParent(parent);
159:                        }
160:                        b.baseName = baseName;
161:                        b.localeID = localeID;
162:
163:                    } catch (ClassNotFoundException e) {
164:
165:                        final String resName = name.replace('.', '/')
166:                                + ".properties";
167:                        InputStream stream = (InputStream) java.security.AccessController
168:                                .doPrivileged(new java.security.PrivilegedAction() {
169:                                    public Object run() {
170:                                        if (cl != null) {
171:                                            return cl
172:                                                    .getResourceAsStream(resName);
173:                                        } else {
174:                                            return ClassLoader
175:                                                    .getSystemResourceAsStream(resName);
176:                                        }
177:                                    }
178:                                });
179:                        if (stream != null) {
180:                            // make sure it is buffered
181:                            stream = new java.io.BufferedInputStream(stream);
182:                            try {
183:                                b = new ResourceBundleWrapper(
184:                                        new PropertyResourceBundle(stream));
185:                                if (parent != null) {
186:                                    b.setParent(parent);
187:                                }
188:                                b.baseName = baseName;
189:                                b.localeID = localeID;
190:                            } catch (Exception ex) {
191:                                // throw away exception
192:                            } finally {
193:                                try {
194:                                    stream.close();
195:                                } catch (Exception ex) {
196:                                    // throw away exception
197:                                }
198:                            }
199:                        }
200:
201:                        // if a bogus locale is passed then the parent should be
202:                        // the default locale not the root locale!
203:                        if (b == null) {
204:                            String defaultName = defaultLocale.toString();
205:                            if (localeID.length() > 0
206:                                    && localeID.indexOf('_') < 0
207:                                    && defaultName.indexOf(localeID) == -1) {
208:                                b = (ResourceBundleWrapper) loadFromCache(cl,
209:                                        baseName + "_" + defaultName,
210:                                        defaultLocale);
211:                                if (b == null) {
212:                                    b = (ResourceBundleWrapper) instantiateBundle(
213:                                            baseName, defaultName, cl,
214:                                            disableFallback);
215:                                }
216:                            }
217:                        }
218:                        // if still could not find the bundle then return the parent
219:                        if (b == null) {
220:                            b = parent;
221:                        }
222:                    } catch (Exception e) {
223:                        if (DEBUG)
224:                            System.out.println("failure");
225:                        if (DEBUG)
226:                            System.out.println(e);
227:                    }
228:
229:                    addToCache(cl, name, defaultLocale, b);
230:                }
231:                if (b != null) {
232:                    b.initKeysVector();
233:                } else {
234:                    if (DEBUG)
235:                        System.out.println("Returning null for " + baseName
236:                                + "_" + localeID);
237:                }
238:
239:                return b;
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.