Source Code Cross Referenced for ExtendedProperties.java in  » Profiler » JMeasurement » de » mcs » utils » 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 » Profiler » JMeasurement » de.mcs.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MCS Media Computer Software Copyright (c) 2007 by MCS
003:         * -------------------------------------- Created on 15.01.2007 by w.klaas
004:         * 
005:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006:         * use this file except in compliance with the License. You may obtain a copy of
007:         * the License at
008:         * 
009:         * http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014:         * License for the specific language governing permissions and limitations under
015:         * the License.
016:         */
017:        /**
018:         * 
019:         */package de.mcs.utils;
020:
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.io.IOException;
024:        import java.util.Date;
025:        import java.util.Properties;
026:
027:        /**
028:         * This class extands the normal properties class with functions to directly get
029:         * simple types.
030:         * 
031:         * @author w.klaas
032:         * 
033:         */
034:        public class ExtendedProperties extends Properties {
035:
036:            /**
037:             * Constructor for directly loaing properties from file.
038:             * 
039:             * @param file
040:             *            the file to load properties from.
041:             * @throws IOException
042:             *             if something goes wrong.
043:             */
044:            public ExtendedProperties(final File file) throws IOException {
045:                super ();
046:                load(new FileInputStream(file));
047:            }
048:
049:            /**
050:             * Simple Constructor.
051:             */
052:            public ExtendedProperties() {
053:                super ();
054:            }
055:
056:            /**
057:             * directly getting boolean value.
058:             * 
059:             * @param key
060:             *            the property to get.
061:             * @return the desired boolean value.
062:             */
063:            public final boolean getBool(final String key) {
064:                return Boolean.parseBoolean(getProperty(key));
065:            }
066:
067:            /**
068:             * directly getting boolean value.
069:             * 
070:             * @param key
071:             *            the property to get.
072:             * @param defaultValue
073:             *            the default value to get, if the property is not present.
074:             * @return the desired boolean value.
075:             */
076:            public final boolean getBool(final String key,
077:                    final boolean defaultValue) {
078:                return Boolean.parseBoolean(getProperty(key, Boolean
079:                        .toString(defaultValue)));
080:            }
081:
082:            /**
083:             * directly getting integer value.
084:             * 
085:             * @param key
086:             *            the property to get.
087:             * @return the desired int value.
088:             */
089:            public final int getInt(final String key) {
090:                return NumberHelper.parseInt(getProperty(key));
091:            }
092:
093:            /**
094:             * directly getting integer value.
095:             * 
096:             * @param key
097:             *            the property to get.
098:             * @param defaultValue
099:             *            the default value to get, if the property is not present.
100:             * @return the desired int value.
101:             */
102:            public final int getInt(final String key, final int defaultValue) {
103:                return NumberHelper.parseInt(getProperty(key, Integer
104:                        .toString(defaultValue)));
105:            }
106:
107:            /**
108:             * directly getting integer value.
109:             * 
110:             * @param key
111:             *            the property to get.
112:             * @param defaultValue
113:             *            the default value to get, if the property is not present.
114:             * @return the desired int value.
115:             */
116:            public final int getInt(final String key, final String defaultValue) {
117:                return NumberHelper.parseInt(getProperty(key, defaultValue));
118:            }
119:
120:            /**
121:             * directly getting long value.
122:             * 
123:             * @param key
124:             *            the property to get.
125:             * @return the desired long value.
126:             */
127:            public final long getLong(final String key) {
128:                return Long.parseLong(getProperty(key));
129:            }
130:
131:            /**
132:             * directly getting long value.
133:             * 
134:             * @param key
135:             *            the property to get.
136:             * @param defaultValue
137:             *            the default value to get, if the property is not present.
138:             * @return the desired long value.
139:             */
140:            public final long getLong(final String key, final long defaultValue) {
141:                return Long.parseLong(getProperty(key, Long
142:                        .toString(defaultValue)));
143:            }
144:
145:            /**
146:             * directly getting a file value.
147:             * 
148:             * @param key
149:             *            the property to get.
150:             * @return the desired file.
151:             */
152:            public final File getFile(final String key) {
153:                if (containsKey(key)) {
154:                    return new File(getProperty(key));
155:                } else {
156:                    return null;
157:                }
158:            }
159:
160:            /**
161:             * directly getting a file value.
162:             * 
163:             * @param key
164:             *            the property to get.
165:             * @param defaultValue
166:             *            the default value to get, if the property is not present.
167:             * @return the desired file.
168:             */
169:            public final File getFile(final String key, final File defaultValue) {
170:                return new File(
171:                        getProperty(key, defaultValue.getAbsolutePath()));
172:            }
173:
174:            /**
175:             * directly getting a string array value.
176:             * 
177:             * @param key
178:             *            the property to get.
179:             * @return the desired string array.
180:             */
181:            public final String[] getStrings(final String key) {
182:                String value = getProperty(key);
183:                if (value != null) {
184:                    return StringUtils.csvStringToArray(value, ',', '"');
185:                }
186:                return null;
187:            }
188:
189:            /**
190:             * directly getting a string array value.
191:             * 
192:             * @param key
193:             *            the property to get.
194:             * @param defaultValue
195:             *            the default value to get, if the property is not present.
196:             * @return the desired string array.
197:             */
198:            public final String[] getStrings(final String key,
199:                    final String[] defaultValue) {
200:                String value = getProperty(key);
201:                if (value != null) {
202:                    return StringUtils.csvStringToArray(value, ',', '"');
203:                }
204:                return defaultValue;
205:            }
206:
207:            /**
208:             * directly getting integer value.
209:             * 
210:             * @param key
211:             *            the property to get.
212:             * @param defaultValue
213:             *            the default value to get, if the property is not present.
214:             * @return the desired int value.
215:             */
216:            public final long getMSec(final String key,
217:                    final String defaultValue) {
218:                return NumberHelper.parseTime(getProperty(key, defaultValue));
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.