Source Code Cross Referenced for DatabaseSettings.java in  » Content-Management-System » harmonise » org » openharmonise » rm » dsi » 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 » Content Management System » harmonise » org.openharmonise.rm.dsi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.rm.dsi;
020:
021:        import java.io.*;
022:        import java.util.*;
023:        import java.util.logging.*;
024:
025:        import org.openharmonise.rm.config.*;
026:
027:        /**
028:         * Wraps the database connection properties.
029:         *  
030:         * @author Matt Treanor
031:         * @author jejking
032:         * @version $Revision: 1.3 $
033:         *
034:         */
035:        public class DatabaseSettings {
036:
037:            /**
038:             * Constant holding the name of the properties file - harmonise.properties
039:             */
040:            public static final String PROPERTIES_FILENAME = "/harmonise.properties";
041:            /**
042:             * The properties file.
043:             */
044:            private File properties_file;
045:
046:            /**
047:             * Logger for this class
048:             */
049:            private static Logger logger = Logger
050:                    .getLogger(DatabaseSettings.class.getName());
051:
052:            private String dsiClass = null;
053:            private String dbUrl = null;
054:            private String dbPwd = null;
055:            private String dbDriver = null;
056:            private String dbUser = null;
057:
058:            private static DatabaseSettings instance;
059:
060:            /**
061:             * Constructs and configures instance using the params given using Contructor injection pattern.
062:             * 
063:             * @param dbUser
064:             * @param dbPassword
065:             * @param dbUrl
066:             * @param dbDriver
067:             * @param dsiClass
068:             * @throws ConfigException
069:             */
070:            public static void createDatabaseSettings(String dbUser,
071:                    String dbPwd, String dbUrl, String dbDriver, String dsiClass)
072:                    throws ConfigException {
073:                // check none are null or empty strings as an initial sanity check on input 
074:                instance = new DatabaseSettings();
075:                instance.setDbUser(dbUser);
076:                instance.setDbPwd(dbPwd);
077:                instance.setDbUrl(dbUrl);
078:                instance.setDbDriver(dbDriver);
079:                instance.setDsiClass(dsiClass);
080:            }
081:
082:            /**
083:             * Constructs an instance of <code>DatabaseSettings</code>
084:             * 
085:             * @throws ConfigException if an error occurs creating the
086:             * <code>PropertyResourceBundle</code>
087:             */
088:            private DatabaseSettings() throws ConfigException {
089:            }
090:
091:            public static void createDatabaseSettingsFromFile()
092:                    throws ConfigException {
093:                Properties props = new Properties();
094:
095:                String classpath = System.getProperty("java.class.path");
096:                StringTokenizer paths = new StringTokenizer(classpath,
097:                        File.pathSeparator);
098:                File propertiesFile = null;
099:                boolean found = false;
100:                while (!found && paths.hasMoreTokens()) {
101:                    String path = paths.nextToken();
102:                    propertiesFile = new File(path, "harmonise.properties");
103:                    found = propertiesFile.exists();
104:                }
105:                if (found) {
106:
107:                    try {
108:                        props.load(new FileInputStream(propertiesFile));
109:                    } catch (FileNotFoundException e) {
110:                        throw new ConfigException(e);
111:                    } catch (IOException e) {
112:                        throw new ConfigException(e);
113:                    }
114:                    instance = new DatabaseSettings();
115:                    instance
116:                            .setDbUser(props
117:                                    .getProperty(DataStoreInterfaceFactory.DBUSR_PNAME));
118:                    instance
119:                            .setDbPwd(props
120:                                    .getProperty(DataStoreInterfaceFactory.DBPWD_PNAME));
121:                    instance
122:                            .setDbUrl(props
123:                                    .getProperty(DataStoreInterfaceFactory.DBURL_PNAME));
124:                    instance
125:                            .setDbDriver(props
126:                                    .getProperty(DataStoreInterfaceFactory.DBDRV_PNAME));
127:                    instance.setDsiClass(props
128:                            .getProperty(DataStoreInterfaceFactory.DSI_PNAME));
129:
130:                }
131:            }
132:
133:            /**
134:             * Returns the singleton instance of this class
135:             * 
136:             * @return the singleton instance of this class
137:             * @throws ConfigException if an error occurs creating the singleton instance
138:             */
139:            public static DatabaseSettings getInstance() throws ConfigException {
140:                /*
141:                 * Logic here is simple. If, earlier in the object lifecycle, something
142:                 * has called createDatabaseSettings and injected configuration params, then 
143:                 * the object created will be returned. This option can be taken by, for example,
144:                 * ServletContextListener on context startup.
145:                 * 
146:                 * 
147:                 * Else, we will attempt to read the configuration file and set our properties from that,
148:                 * construct a new instance and return that. This option can be taken when testing,
149:                 * for example.
150:                 * 
151:                 */
152:                if (instance == null) {
153:                    createDatabaseSettingsFromFile();
154:                }
155:                return instance;
156:            }
157:
158:            /**
159:             * @return Returns the dbDriver.
160:             */
161:            public String getDbDriver() {
162:                return dbDriver;
163:            }
164:
165:            /**
166:             * @param dbDriver The dbDriver to set.
167:             */
168:            private void setDbDriver(String dbDriver) {
169:                if (dbDriver == null || dbDriver.length() == 0) {
170:                    throw new IllegalArgumentException(
171:                            "dbDriver may not be null or zero length");
172:                }
173:                this .dbDriver = dbDriver;
174:            }
175:
176:            /**
177:             * @return Returns the dbPwd.
178:             */
179:            public String getDbPwd() {
180:                return dbPwd;
181:            }
182:
183:            /**
184:             * @param dbPwd The dbPwd to set.
185:             */
186:            private void setDbPwd(String dbPwd) {
187:                if (dbPwd == null || dbPwd.length() == 0) {
188:                    throw new IllegalArgumentException(
189:                            "dbPwd may not be null or zero length");
190:                }
191:                this .dbPwd = dbPwd;
192:            }
193:
194:            /**
195:             * @return Returns the dbUrl.
196:             */
197:            public String getDbUrl() {
198:                return dbUrl;
199:            }
200:
201:            /**
202:             * @param dbUrl The dbUrl to set.
203:             */
204:            private void setDbUrl(String dbUrl) {
205:                if (dbUrl == null || dbUrl.length() == 0) {
206:                    throw new IllegalArgumentException(
207:                            "dbUrl may not be null or zero length");
208:                }
209:                this .dbUrl = dbUrl;
210:            }
211:
212:            /**
213:             * @return Returns the dbUser.
214:             */
215:            public String getDbUser() {
216:                return dbUser;
217:            }
218:
219:            /**
220:             * @param dbUser The dbUser to set.
221:             */
222:            private void setDbUser(String dbUser) {
223:                if (dbUser == null || dbUser.length() == 0) {
224:                    throw new IllegalArgumentException(
225:                            "dbUser may not be null or zero length");
226:                }
227:                this .dbUser = dbUser;
228:            }
229:
230:            /**
231:             * @return Returns the dsiClass.
232:             */
233:            public String getDsiClass() {
234:                return dsiClass;
235:            }
236:
237:            /**
238:             * @param dsiClass The dsiClass to set.
239:             */
240:            private void setDsiClass(String dsiClass) {
241:                if (dsiClass == null || dsiClass.length() == 0) {
242:                    throw new IllegalArgumentException(
243:                            "dsiClass may not be null or zero length");
244:                }
245:                this.dsiClass = dsiClass;
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.