Source Code Cross Referenced for Configuration.java in  » Database-ORM » castor » org » castor » ddlgen » 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 ORM » castor » org.castor.ddlgen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Le Duc Bao, Ralf Joachim
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package org.castor.ddlgen;
017:
018:        import java.io.IOException;
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:        import java.util.Enumeration;
022:        import java.util.Properties;
023:
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:
027:        /** 
028:         * Handle the configuration for DDL generator including load configuration files,
029:         * manage configuration values.
030:         * 
031:         * @author <a href="mailto:leducbao AT gmail DOT com">Le Duc Bao</a>
032:         * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
033:         * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
034:         * @since 1.1
035:         */
036:        public class Configuration {
037:            //--------------------------------------------------------------------------
038:
039:            /** The <a href="http://jakarta.apache.org/commons/logging/">Jakarta
040:             *  Commons Logging</a> instance used for all logging. */
041:            private static final Log LOG = LogFactory
042:                    .getLog(Configuration.class);
043:
044:            /** String representation of boolean <code>true</code>. */
045:            public static final String TRUE = "true";
046:
047:            /** String representation of boolean <code>false</code>. */
048:            public static final String FALSE = "false";
049:
050:            //--------------------------------------------------------------------------
051:
052:            /** 
053:             * handle configuration.
054:             */
055:            private final Properties _conf = new Properties();
056:
057:            //--------------------------------------------------------------------------
058:
059:            /**
060:             * Constructor for Configuration.
061:             */
062:            public Configuration() {
063:                super ();
064:
065:                addProperties(System.getProperties());
066:            }
067:
068:            //--------------------------------------------------------------------------
069:
070:            /**
071:             * get boolean value associated with key in the configuration files.
072:             * 
073:             * @param key key
074:             * @return return value associated with key. If not exists, throw an
075:             *         exception
076:             * @throws WrongFormatException format error
077:             * @throws KeyNotFoundException key error
078:             */
079:            public final boolean getBoolValue(final String key)
080:                    throws WrongFormatException, KeyNotFoundException {
081:                String value = this .getStringValue(key);
082:
083:                if (value == null) {
084:                    throw new KeyNotFoundException("can not found key " + key);
085:                }
086:
087:                if (TRUE.equals(value)) {
088:                    return true;
089:                }
090:
091:                if (FALSE.equals(value)) {
092:                    return false;
093:                }
094:
095:                throw new WrongFormatException(
096:                        "require boolean (true/false), receive " + value
097:                                + " for key=" + key);
098:            }
099:
100:            /**
101:             * get boolean value associated with key in the configuration files.
102:             * 
103:             * @param key key
104:             * @param defaultValue default value
105:             * @return return value associated with key. If not exists, return the default value
106:             */
107:            public final boolean getBoolValue(final String key,
108:                    final boolean defaultValue) {
109:                String value = null;
110:                try {
111:                    value = this .getStringValue(key);
112:                } catch (KeyNotFoundException e) {
113:                    return defaultValue;
114:                }
115:
116:                if (value == null) {
117:                    return defaultValue;
118:                }
119:
120:                if (TRUE.equals(value)) {
121:                    return true;
122:                }
123:
124:                if (FALSE.equals(value)) {
125:                    return false;
126:                }
127:
128:                return defaultValue;
129:            }
130:
131:            /**
132:             * Get property with given name as Integer value. If property is not
133:             * available or can not be interpreted as integer null will be returned.
134:             * 
135:             * @param name Name of the property.
136:             * @return The configured Integer property or null if property is not
137:             *         available or can not be interpreted as integer.
138:             */
139:            public final Integer getInteger(final String name) {
140:                String value = _conf.getProperty(name);
141:                if (value == null) {
142:                    return null;
143:                }
144:                try {
145:                    return Integer.valueOf(value);
146:                } catch (NumberFormatException ex) {
147:                    return null;
148:                }
149:            }
150:
151:            /**
152:             * get String value associated with key in the configuration files.
153:             * 
154:             * @param key key
155:             * @return return value associated with key. If not exists, throw an
156:             *         exception
157:             * @throws KeyNotFoundException key error
158:             */
159:            public final String getStringValue(final String key)
160:                    throws KeyNotFoundException {
161:                String value = (String) _conf.get(key);
162:                if (value == null || "".equals(value)) {
163:                    throw new KeyNotFoundException(
164:                            "Can not find value correspondence to " + key);
165:                }
166:                return value;
167:            }
168:
169:            /**
170:             * get String value associated with key in the configuration files.
171:             * 
172:             * @param key key
173:             * @param defaultValue default value
174:             * @return return value associated with key. If not exists, return default
175:             *         value
176:             */
177:            public final String getStringValue(final String key,
178:                    final String defaultValue) {
179:                String value = (String) _conf.get(key);
180:                if (value == null || "".equals(value)) {
181:                    value = defaultValue;
182:                }
183:                return value;
184:            }
185:
186:            /**
187:             * add properties (key, value) for configuration, the existed item will
188:             * be overwrited.
189:             * @param props properties
190:             */
191:            public final void addProperties(final Properties props) {
192:                if (props != null) {
193:                    Object key;
194:                    Object value;
195:                    for (Enumeration e = props.keys(); e.hasMoreElements();) {
196:                        key = e.nextElement();
197:                        value = props.get(key);
198:                        _conf.put(key, value);
199:                    }
200:                }
201:            }
202:
203:            /**
204:             * add properties (key, value) for configuration, the existed item will
205:             * be overwrited.
206:             * 
207:             * @param filename a properties file
208:             * @throws GeneratorException generator error
209:             */
210:            public final void addProperties(final String filename)
211:                    throws GeneratorException {
212:                Properties props = new Properties();
213:                URL url = null;
214:                try {
215:                    try {
216:                        url = new URL(filename);
217:                    } catch (MalformedURLException ex) {
218:                        url = getClass().getClassLoader().getResource(filename);
219:                    }
220:                    if (url != null) {
221:                        props.load(url.openStream());
222:                        addProperties(props);
223:                    } else {
224:                        String msg = "Could not obtain the configuration file '"
225:                                + filename + "' from the Castor JAR.";
226:                        LOG.error(msg);
227:                        throw new GeneratorException(msg);
228:                    }
229:                } catch (IOException ex) {
230:                    String msg = "Could not read the configuration file '"
231:                            + url.toExternalForm() + "' from the Castor JAR.";
232:                    LOG.error(msg, ex);
233:                    throw new GeneratorException(msg, ex);
234:                }
235:            }
236:
237:            /**
238:             * set property value, this will overwrite the loaded value.
239:             * 
240:             * @param key key
241:             * @param value value
242:             */
243:            public final void setProperty(final String key, final String value) {
244:                _conf.put(key, value);
245:            }
246:
247:            //--------------------------------------------------------------------------
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.