Source Code Cross Referenced for Config.java in  » Net » GNetWatch » net » fenyo » gnetwatch » 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 » Net » GNetWatch » net.fenyo.gnetwatch 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GNetWatch
003:         * Copyright 2006, 2007 Alexandre Fenyo
004:         * gnetwatch@fenyo.net
005:         *
006:         * This file is part of GNetWatch.
007:         *
008:         * GNetWatch is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License as published by
010:         * the Free Software Foundation; either version 2 of the License, or
011:         * (at your option) any later version.
012:         *
013:         * GNetWatch is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with GNetWatch; if not, write to the Free Software
020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021:         */
022:
023:        package net.fenyo.gnetwatch;
024:
025:        import java.io.*;
026:        import java.util.*;
027:        import java.text.*;
028:        import org.hibernate.cfg.*;
029:        import org.apache.commons.logging.*;
030:
031:        /**
032:         * Instances of this class maintain general parameters like configuration properties.
033:         * @author Alexandre Fenyo
034:         * @version $Id: Config.java,v 1.7 2007/03/03 00:38:19 fenyo Exp $
035:         */
036:
037:        public class Config {
038:            private static Log log = LogFactory.getLog(Config.class);
039:
040:            // Configuration properties.
041:            private final Properties properties;
042:
043:            // Localization state variables.
044:            private Locale locale = null;
045:            private ResourceBundle bundle = null;
046:
047:            private boolean needEnd = false;
048:
049:            /**
050:             * Constructor.
051:             * Reads the configuration properties from the initialization file.
052:             * main thread
053:             * @param none.
054:             * @throws IOException file not found.
055:             */
056:            public Config() throws IOException {
057:                properties = new Properties();
058:                properties.loadFromXML(new FileInputStream("config.xml"));
059:
060:                locale = new Locale(getProperty("language"),
061:                        getProperty("country"));
062:                bundle = ResourceBundle.getBundle("i18n", locale);
063:            }
064:
065:            /**
066:             * Declare that the application will exit soon.
067:             * main thread
068:             * @param none.
069:             * @return void.
070:             */
071:            // main thread
072:            public void setEnd() {
073:                needEnd = true;
074:            }
075:
076:            /**
077:             * Checks the application state.
078:             * @param none.
079:             * @return boolean application state.
080:             */
081:            // Background, Capture, Queue, AwtGUI & main threads
082:            public boolean isEnd() {
083:                return needEnd;
084:            }
085:
086:            /**
087:             * Gets a property value.
088:             * @param key.
089:             * @return String property value.
090:             */
091:            public String getProperty(final String key) {
092:                return properties.getProperty("net.fenyo." + key);
093:            }
094:
095:            /**
096:             * Gets a property value.
097:             * @param key key.
098:             * @param dflt default value.
099:             * @return String property value.
100:             */
101:            public String getProperty(final String key, final String dflt) {
102:                return properties.getProperty("net.fenyo." + key, dflt);
103:            }
104:
105:            /**
106:             * Returns the locale associated with this configuration.
107:             * @param none.
108:             * @return Locale locale.
109:             */
110:            public Locale getLocale() {
111:                return locale;
112:            }
113:
114:            /**
115:             * Returns the i18n resource bundle associated with this configuration.
116:             * @param none.
117:             * @return ResourceBundle resource bundle.
118:             */
119:            public ResourceBundle getBundle() {
120:                return bundle;
121:            }
122:
123:            /**
124:             * Returns an i18n message.
125:             * @param key i18n key.
126:             * @return String locale dependant message.
127:             */
128:            public String getString(final String key) {
129:                return bundle.getString(key);
130:            }
131:
132:            /**
133:             * Returns an i18n message.
134:             * @param key i18n key.
135:             * @param params array of arguments to scatter in the i18n locale dependant message.
136:             * @return String locale dependant message.
137:             */
138:            public String getPattern(final String key, final Object[] params) {
139:                final MessageFormat formatter = new MessageFormat("");
140:                formatter.setLocale(locale);
141:                formatter.applyPattern(getString(key));
142:                return formatter.format(params);
143:            }
144:
145:            /**
146:             * Returns an i18n message.
147:             * @param key i18n key.
148:             * @param arg argument for locale dependant message.
149:             * @return String locale dependant message.
150:             */
151:            public String getPattern(final String key, final Object arg) {
152:                Object[] msgArgs = { arg };
153:                return getPattern(key, msgArgs);
154:            }
155:
156:            /**
157:             * Returns an i18n message.
158:             * @param key i18n key.
159:             * @param arg1 argument for locale dependant message.
160:             * @param arg2 argument for locale dependant message.
161:             * @return String locale dependant message.
162:             */
163:            public String getPattern(final String key, final Object arg1,
164:                    final Object arg2) {
165:                Object[] msgArgs = { arg1, arg2 };
166:                return getPattern(key, msgArgs);
167:            }
168:
169:            /**
170:             * Returns an i18n message.
171:             * @param key i18n key.
172:             * @param arg1 argument for locale dependant message.
173:             * @param arg2 argument for locale dependant message.
174:             * @param arg3 argument for locale dependant message.
175:             * @return String locale dependant message.
176:             */
177:            public String getPattern(final String key, final Object arg1,
178:                    final Object arg2, final Object arg3) {
179:                Object[] msgArgs = { arg1, arg2, arg3 };
180:                return getPattern(key, msgArgs);
181:            }
182:
183:            /**
184:             * Returns an i18n message.
185:             * @param key i18n key.
186:             * @param arg1 argument for locale dependant message.
187:             * @param arg2 argument for locale dependant message.
188:             * @param arg3 argument for locale dependant message.
189:             * @param arg4 argument for locale dependant message.
190:             * @return String locale dependant message.
191:             */
192:            public String getPattern(final String key, final Object arg1,
193:                    final Object arg2, final Object arg3, final Object arg4) {
194:                Object[] msgArgs = { arg1, arg2, arg3, arg4 };
195:                return getPattern(key, msgArgs);
196:            }
197:
198:            /**
199:             * Returns an i18n message.
200:             * @param key i18n key.
201:             * @param arg1 argument for locale dependant message.
202:             * @param arg2 argument for locale dependant message.
203:             * @param arg3 argument for locale dependant message.
204:             * @param arg4 argument for locale dependant message.
205:             * @param arg5 argument for locale dependant message.
206:             * @return String locale dependant message.
207:             */
208:            public String getPattern(final String key, final Object arg1,
209:                    final Object arg2, final Object arg3, final Object arg4,
210:                    final Object arg5) {
211:                Object[] msgArgs = { arg1, arg2, arg3, arg4, arg5 };
212:                return getPattern(key, msgArgs);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.