Source Code Cross Referenced for ResourceManager.java in  » Source-Control » jcvsweb » com » ice » 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 » Source Control » jcvsweb » com.ice.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         ** ResourceBundle Manager Utility class.
003:         ** Authored in 1999 by Timothy Gerard Endres.
004:         ** 
005:         ** This Java Class source has been placed in the public domain.
006:         ** 
007:         */
008:
009:        package com.ice.util;
010:
011:        import java.text.MessageFormat;
012:        import java.util.Hashtable;
013:        import java.util.ResourceBundle;
014:        import java.util.MissingResourceException;
015:
016:        /**
017:         * This class attempts to manage a set of ResourceBundles. For example,
018:         * an application may have one set of resources for the GUI elements in
019:         * the application, and another set of resources for context help, and
020:         * yet another set for builtin scripts.
021:         *
022:         * Each ResourceManager instance is identified by an id. Class methods
023:         * provided to allow quick access to any ResourceManager by id.
024:         *
025:         * ResourceManager, aside from manager multiple instances by id, also
026:         * add an additional method beyond that provided by ResourceBundle -
027:         * getFormat(). This method is like getString() in that is returns a
028:         * String resource, however, getFormat() formats the resource using
029:         * arguments passed to the method. This makes it easy to use resources
030:         * for both constant strings and formatted strings.
031:         *
032:         * @version $Revision: 1.1 $
033:         * @author Timothy Gerard Endres,
034:         *  <a href="mailto:time@ice.com">time@ice.com</a>.
035:         */
036:
037:        public class ResourceManager {
038:            static public final String RCS_ID = "$Id: ResourceManager.java,v 1.1 2000/01/28 02:24:45 time Exp $";
039:            static public final String RCS_REV = "$Revision: 1.1 $";
040:
041:            /**
042:             * The table of all ResourceManagers keyed by 'id'.
043:             */
044:            private static Hashtable bundles;
045:
046:            /**
047:             * Set to true to get processing debugging on stderr.
048:             */
049:            private boolean debug;
050:
051:            /**
052:             * The resource bundle's name. Used for easy identification.
053:             */
054:            private String name;
055:
056:            /**
057:             * The resource bundle.
058:             */
059:            private ResourceBundle rsrc;
060:
061:            /**
062:             * Initializes the class by instantiating the bundles Hashtable.
063:             * Your application must call this class method only once, and
064:             * before calling any other methods in this class.
065:             */
066:
067:            public static void initialize() {
068:                ResourceManager.bundles = new Hashtable();
069:            }
070:
071:            /**
072:             * Load a PropertyResourceBundle using the name, and add it to the
073:             * bundles Hashtable keyed by id.
074:             *
075:             * @param id The id of the ResourceManager. This is used as the
076:             *  key into the bundles table.
077:             * @param name The name of the ResourceManager. This is used to
078:             *  load the resource bundle.
079:             */
080:            public static void load(String id, String name) {
081:                try {
082:                    ResourceBundle rsrc = ResourceBundle.getBundle(name);
083:                    ResourceManager rMgr = new ResourceManager(name, rsrc);
084:                    ResourceManager.bundles.put(id, rMgr);
085:                } catch (MissingResourceException ex) {
086:                    ex.printStackTrace();
087:                }
088:            }
089:
090:            /**
091:             * Get a ResourceManager keyed by id.
092:             *
093:             * @param id The id of the ResourceManager to be returned.
094:             * @return The ResourceManager identied by id.
095:             */
096:            public static ResourceManager get(String id) {
097:                return (ResourceManager) ResourceManager.bundles.get(id);
098:            }
099:
100:            /**
101:             * Put a ResourceManager into the bundles Hashtable, keyed by id.
102:             *
103:             * @param id The id used to identify this ResourceManager.
104:             * @param rMgr The resource manager to be managed.
105:             * @return The previous ResourceManager identied by id, or null.
106:             */
107:            public static ResourceManager put(String id, ResourceManager rMgr) {
108:                return (ResourceManager) ResourceManager.bundles.put(id, rMgr);
109:            }
110:
111:            /**
112:             * This constructor is not used.
113:             */
114:            private ResourceManager() {
115:            }
116:
117:            /**
118:             * Construct a ResourceManager with the given name and ResourceBundle.
119:             *
120:             * @param name The (display) name of this resource bundle.
121:             * @param rsrc The resource bundle to be managed.
122:             */
123:            public ResourceManager(String name, ResourceBundle rsrc)
124:                    throws MissingResourceException {
125:                this .name = name;
126:                this .rsrc = rsrc;
127:            }
128:
129:            /**
130:             * Set the debugging flag for this ResourceManager. If debugging is
131:             * set to true, debugging will be printed to System.err.
132:             *
133:             * @param debug The new debugging setting.
134:             */
135:            public void setDebug(boolean debug) {
136:                this .debug = debug;
137:            }
138:
139:            /**
140:             * Get a string resource from the ResourceBundle that this
141:             * ResourceManager is managing.
142:             *
143:             * @param key The key of the resource to retrieve.
144:             * @return The resource string.
145:             */
146:            public String getString(String key) {
147:                return this .rsrc.getString(key);
148:            }
149:
150:            /**
151:             * Format a string resource from the ResourceBundle that this
152:             * ResourceManager is managing. The key is used to retrieve a
153:             * resource that is the format, which is then formatted using
154:             * the provided arguments.
155:             *
156:             * @param key The key of the resource that is the message format.
157:             * @param args The arguments to be used to format the message.
158:             * @return The formatted resource message.
159:             */
160:
161:            public String getFormat(String key, Object[] args) {
162:                return MessageFormat.format(this.rsrc.getString(key), args);
163:            }
164:
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.