Source Code Cross Referenced for SystemProperties.java in  » Database-Client » executequery » org » underworldlabs » 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 » Database Client » executequery » org.underworldlabs.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SystemProperties.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.underworldlabs.util;
023:
024:        import java.awt.Color;
025:        import java.io.IOException;
026:        import java.util.HashMap;
027:        import java.util.Map;
028:        import java.util.Properties;
029:
030:        /* ----------------------------------------------------------
031:         * CVS NOTE: Changes to the CVS repository prior to the 
032:         *           release of version 3.0.0beta1 has meant a 
033:         *           resetting of CVS revision numbers.
034:         * ----------------------------------------------------------
035:         */
036:
037:        /**
038:         * A convenience class to store and return system properties
039:         * not limited to the <code>String</code> datatype provided
040:         * by <code>java.util.Properties</code>.<br>
041:         * It provides the set and get methods for integer, string,
042:         * boolean and colour datatypes [and objects] where applicable.
043:         * 
044:         * @author   Takis Diakoumis
045:         * @version  $Revision: 1.4 $
046:         * @date     $Date: 2006/05/14 06:56:07 $
047:         */
048:        public class SystemProperties {
049:
050:            /** properties cache */
051:            private static Map<String, Properties> map;
052:
053:            private SystemProperties() {
054:            }
055:
056:            /**
057:             * Loads and stores in the cache the properties file at the 
058:             * specified file system path. The properties are stored in the
059:             * cache under the specified name and accessed using that name.
060:             *
061:             * @param name - the cache name to store the props
062:             * @param path - the file system to the properties file
063:             */
064:            public static void loadProperties(String name, String path) {
065:                try {
066:                    Properties properties = FileUtils.loadProperties(path);
067:                    if (properties != null) {
068:
069:                        if (map == null) {
070:                            map = new HashMap<String, Properties>();
071:                        }
072:
073:                        map.put(name, properties);
074:                    }
075:                } catch (IOException e) {
076:                    throw new RuntimeException(e);
077:                }
078:            }
079:
080:            /**
081:             * Loads and stores in the cache the properties file at the 
082:             * specified file system path. The properties are stored in the
083:             * cache under the specified name and accessed using that name.
084:             *
085:             * @param name - the cache name to store the props
086:             * @param path - the file system to the properties file
087:             */
088:            public static void loadProperties(String name, String path,
089:                    Properties defaults) {
090:                try {
091:                    Properties properties = FileUtils.loadProperties(path,
092:                            defaults);
093:                    if (properties != null) {
094:
095:                        if (map == null) {
096:                            map = new HashMap<String, Properties>();
097:                        }
098:
099:                        map.put(name, properties);
100:                    }
101:                } catch (IOException e) {
102:                    throw new RuntimeException(e);
103:                }
104:            }
105:
106:            /**
107:             * Loads and stores in the cache the properties file at the 
108:             * specified package resource path. The properties are stored 
109:             * in the cache under the specified name and accessed using that name.
110:             *
111:             * @param name - the cache name to store the props
112:             * @param path - the package resource path to the properties file
113:             */
114:            public static void loadPropertiesResource(String name, String path) {
115:                try {
116:                    Properties properties = FileUtils
117:                            .loadPropertiesResource(path);
118:                    if (properties != null) {
119:
120:                        if (map == null) {
121:                            map = new HashMap<String, Properties>();
122:                        }
123:
124:                        map.put(name, properties);
125:                    }
126:                } catch (IOException e) {
127:                    throw new RuntimeException(e);
128:                }
129:            }
130:
131:            /**
132:             * Returns the properties object with the specified name in the cache.
133:             *
134:             * @param name - the name assigned to the properties bundle
135:             * @return the properties object or null if doesn't exist
136:             */
137:            public static Properties getProperties(String name) {
138:                if (map.containsKey(name)) {
139:                    return map.get(name);
140:                }
141:                return null;
142:            }
143:
144:            public static final boolean containsKey(String propertiesName,
145:                    String key) {
146:                Properties properties = getProperties(propertiesName);
147:                if (properties != null) {
148:                    return properties.containsKey(key);
149:                }
150:                return false;
151:            }
152:
153:            /**
154:             * Sets a property with a <code>String</code> value<br>
155:             *
156:             * @param key - the property key
157:             * @param value - the property value
158:             */
159:            public static final void setStringProperty(String propertiesName,
160:                    String key, String value) {
161:                Properties properties = getProperties(propertiesName);
162:                if (properties != null) {
163:                    properties.setProperty(key, value);
164:                }
165:            }
166:
167:            /**
168:             * Sets a property using the <code>Properties</code>
169:             * method <code>setProperty(key, value)</code><br>
170:             *
171:             * @param key - the property key
172:             * @param value - the property value
173:             */
174:            public static final void setProperty(String propertiesName,
175:                    String key, String value) {
176:                Properties properties = getProperties(propertiesName);
177:                if (properties != null) {
178:                    properties.setProperty(key, value);
179:                }
180:            }
181:
182:            /**
183:             * Sets a property with an <code>int</code> value<br>
184:             *
185:             * @param key - the property key
186:             * @param value - the property value
187:             */
188:            public static final void setIntProperty(String propertiesName,
189:                    String key, int value) {
190:                Properties properties = getProperties(propertiesName);
191:                if (properties != null) {
192:                    properties.setProperty(key, Integer.toString(value));
193:                }
194:            }
195:
196:            /**
197:             * Sets a property with a <code>boolean</code> value<br>
198:             *
199:             * @param key - the property key
200:             * @param value - the property value
201:             */
202:            public static final void setBooleanProperty(String propertiesName,
203:                    String key, boolean value) {
204:                Properties properties = getProperties(propertiesName);
205:                if (properties != null) {
206:                    properties.setProperty(key, value ? "true" : "false");
207:                }
208:            }
209:
210:            /**
211:             * Sets a property with a <code>Color</code> value<br>
212:             *
213:             * @param key - the property key
214:             * @param value - the property value
215:             */
216:            public static final void setColourProperty(String propertiesName,
217:                    String key, Color value) {
218:                Properties properties = getProperties(propertiesName);
219:                if (properties != null) {
220:                    properties.setProperty(key, Integer
221:                            .toString(value.getRGB()));
222:                }
223:            }
224:
225:            /**
226:             * Retrieves a property of type <code>int</code><br>
227:             *
228:             * @param key - the property key
229:             * @return - the <code>int</code> value
230:             */
231:            public static final int getIntProperty(String propertiesName,
232:                    String key) {
233:                Properties properties = getProperties(propertiesName);
234:                if (properties != null) {
235:                    return Integer.parseInt(properties.getProperty(key));
236:                }
237:                return -1;
238:            }
239:
240:            /**
241:             * Retrieves a property of type <code>boolean</code><br>
242:             *
243:             * @param key - the property key
244:             * @return the <code>boolean</code> value
245:             */
246:            public static final boolean getBooleanProperty(
247:                    String propertiesName, String key) {
248:                Properties properties = getProperties(propertiesName);
249:                if (properties != null) {
250:                    return Boolean.valueOf(properties.getProperty(key))
251:                            .booleanValue();
252:                }
253:                return false;
254:            }
255:
256:            /**
257:             * Retrieves a property of object type <code>Color</code><br>
258:             *
259:             * @param key - the property key
260:             * @return the <code>Color</code> value
261:             */
262:            public static final Color getColourProperty(String propertiesName,
263:                    String key) {
264:                Properties properties = getProperties(propertiesName);
265:                if (properties != null) {
266:                    return new Color(Integer.parseInt(properties
267:                            .getProperty(key)));
268:                }
269:                return null;
270:            }
271:
272:            /**
273:             * Retrieves a property using the <code>Properties</code>
274:             * method <code>getProperty(key)</code><br>
275:             *
276:             * @param key - the property key
277:             * @return the property value
278:             */
279:            public static final String getProperty(String propertiesName,
280:                    String key) {
281:                Properties properties = getProperties(propertiesName);
282:                if (properties != null) {
283:                    return properties.getProperty(key);
284:
285:                }
286:                return null;
287:            }
288:
289:            /**
290:             * Retrieves a property of object type <code>String</code><br>
291:             *
292:             * @param key - the property key
293:             * @return the <code>String</code> value
294:             */
295:            public static final String getStringProperty(String propertiesName,
296:                    String key) {
297:                return getProperty(propertiesName, key);
298:            }
299:
300:            /**
301:             * Returns the property with the specified name, formatting it with
302:             * the <code>java.text.MessageFormat.format()</code> method.
303:             *
304:             * @param key - the property key
305:             * @param args The positional parameters
306:             */
307:            public static final String getProperty(String propertiesName,
308:                    String name, Object[] args) {
309:
310:                if (name == null) {
311:                    return null;
312:                }
313:
314:                Properties properties = getProperties(propertiesName);
315:                if (properties == null) {
316:                    return null;
317:                }
318:
319:                if (args == null) {
320:                    return properties.getProperty(name, name);
321:                } else {
322:                    return java.text.MessageFormat.format(properties
323:                            .getProperty(name, name), args);
324:                }
325:
326:            }
327:
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.